第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > c#winform如何获取服务器指定文件夹中所有的文件信息 winform 读取某个目录下的所有

c#winform如何获取服务器指定文件夹中所有的文件信息 winform 读取某个目录下的所有

时间:2020-08-04 23:18:45

相关推荐

c#winform如何获取服务器指定文件夹中所有的文件信息 winform 读取某个目录下的所有

【实例简介】产品电子报价 功能实现

【实例截图】

【核心代码】

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Collections;

namespace ProductElectronQuote

{

public partial class Frm_Main : Form

{

Hashtable ht = new Hashtable(); //初始化一个哈希表对象

string str; //初始化一个字符串str

public Frm_Main()

{

InitializeComponent();

str = Application.StartupPath "\\Image";//保存商品图片所在的路径

}

private void Form1_Load(object sender, EventArgs e)

{

DirectoryInfo dir = new DirectoryInfo(str);//初始化一个DirectoryInfo类的对象

GetAllFiles(dir); //获取指定路径下的所有文件

foreach (DictionaryEntry de in ht) //循环哈希表中的所有数据

boBox1.Items.Add(de.Key); //向comboBox1中添加内容

}

public void GetAllFiles(DirectoryInfo dir)

{

FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //初始化一个FileSystemInfo类型的实例

foreach (FileSystemInfo i in fileinfo) //循环遍历fileinfo下的所有内容

{

if (i is DirectoryInfo) //当在DirectoryInfo中存在i时

{

GetAllFiles((DirectoryInfo)i); //获取i下的所有文件

}

else//当在DirectoryInfo中不存在i时

{

string str = i.FullName; //记录i的绝对路径

int b = str.LastIndexOf("\\");//获取字符串下与指定项匹配的最后一个索引

string strType = str.Substring(b 1);//获取文件的后缀名

//当图片类型为“jpg”或者“bmp”时

if (strType.Substring(strType.Length - 3).ToLower() == "jpg" || strType.Substring(strType.Length - 3).ToLower() == "bmp")

{

ht.Add(strType.Substring(0, strType.Length - 4), strType);//向哈希表中添加内容

}

}

}

}

private void button1_Click(object sender, EventArgs e)

{

if (ht.Values.Count > 0)

{

showPic(ht[boBox1.Text].ToString());

}

else

{

MessageBox.Show("目前还没有海报信息!!!");

}

}

private void showPic(string name)

{

this.pictureBox1.ImageLocation = str "\\" name;//设置在pictureBox1中显示图片的路径

}

}

}

c#winform如何获取服务器指定文件夹中所有的文件信息 winform 读取某个目录下的所有图片并显示到pictureBox 附完整源码...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。