选择查询 [英] Select Query

查看:61
本文介绍了选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何从我的桌面加载所有文件.
即我必须在选择查询中使用任何关键字在桌面上显示我的所有文件



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

推荐答案

嗨 请根据您的要求更新路径


Hi Please update path as per your requirement


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


选择查询用于查询数据库,而不是桌面.

您是否已经有了一个集合中所有桌面文件的列表?
您可以使用LINQ查询来过滤出集合.
Select queries are used to query a database - not the desktop.

Have you got a list of all the desktop files in a collection already?
You can use LINQ queries to filter out the collection then.


使用 system.io.directory.getfiles 方法获取指定目录中的文件列表. .,

通过Google的以下链接.有很多示例..

^ ]

您无法使用选择查询在桌面上获取文件列表...
use the system.io.directory.getfiles method for get the files list in the specified directory..,

go through the below link in Google., there are so many examples..,

Get File List.. [^]

you can''t get file list in desktop using select query...


这篇关于选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆