本文介绍了选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从我的桌面加载所有文件.
即我必须在选择查询中使用任何关键字在桌面上显示我的所有文件
How to Load all the files from my Desktop.
i.e. I have to show my all files in the desktop by using any keyword in the select query
推荐答案
private static string UPLOADFOLDER = "Uploads";
public void LoadUploadedFiles(ref GridView gv)
{
DataTable dtFiles = GetFilesInDirectory(HttpContext.Current.Server.MapPath(UPLOADFOLDER));
gv.DataSource = dtFiles;
gv.DataBind();
if (dtFiles != null && dtFiles.Rows.Count > 0)
{
double totalSize = Convert.ToDouble(dtFiles.Compute("SUM(Size)", ""));
if (totalSize > 0) lblTotalSize.Text = CalculateFileSize(totalSize);
}
}
public DataTable GetFilesInDirectory(string sourcePath)
{
System.Data.DataTable dtFiles = new System.Data.DataTable();
if ((Directory.Exists(sourcePath)))
{
dtFiles.Columns.Add(new System.Data.DataColumn("Name"));
dtFiles.Columns.Add(new System.Data.DataColumn("Size"));
dtFiles.Columns["Size"].DataType = typeof(double);
dtFiles.Columns.Add(new System.Data.DataColumn("ConvertedSize"));
DirectoryInfo dir = new DirectoryInfo(sourcePath);
foreach (FileInfo files in dir.GetFiles("*.*"))
{
System.Data.DataRow drFile = dtFiles.NewRow();
drFile["Name"] = files.Name;
drFile["Size"] = files.Length;
drFile["ConvertedSize"] = CalculateFileSize(files.Length);
dtFiles.Rows.Add(drFile);
}
}
return dtFiles;
}
如有任何疑问,请让我知道.
如果有帮助,请提供"投票",如果这是正确的答案,请提供"接受答案".:rose:
谢谢,
Imdadhusen
Please do let me know, if you have any doubt.
Please provide "Vote" if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:
Thanks,
Imdadhusen
这篇关于选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!