日期:2014-05-18 浏览次数:20907 次
string[] fs=Directory.GetFiles("你的路径", "*.jpg"); foreach(string s in fs) { //把文件名称加到DataTable中 }
------解决方案--------------------
文件夹就是一颗树.
用遍历树的算法就行了.
------解决方案--------------------
遍历JPG
private void button1_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text.Trim() == "")
{
MessageBox.Show("请输入JPG路径");
return;
}
string srcPath = "D:\\Microsoft SQL Server\\DataBase";
srcPath=textBox1.Text.Trim();
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
foreach (string file in fileList)
{
if (file.Trim().Substring(file.Trim().Length - 3, 3).Trim().ToUpper()=="JPG")
{
bin.AddNew();
cdgv.CurrentRow.Cells["sDish_c"].Value = file.Trim();
}
//if (file.EndsWith("jpg"))
//{
// bin.AddNew();
// cdgv.CurrentRow.Cells["sDish_c"].Value = file.Trim();
//}
//if (file.EndsWith("JPG"))
//{
// bin.AddNew();
// cdgv.CurrentRow.Cells["sDish_c"].Value = file.Trim();
//}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
------解决方案--------------------
同意一楼的