显示位于文件夹中的文件 [英] Displaying a file which is located in a folder
本文介绍了显示位于文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用GridView或asp.net网页中包含删除选项的任何其他控件显示位于文件夹或子文件夹中的文件?
How to display a file which is located in a folder or a subfolder using a GridView or any other control that contains delete option in an asp.net Web Page?
推荐答案
使用以下命令获取文件夹中的文件列表.拥有它后,将其显示在具有所需功能的控件中-网格,树视图,列表视图等.
从目录[C#]中获取文件 [
Use following to get list of files in a folder. Once you have it, display it in a control that has features you want - Grid, Treeview, Listview, etc.
Get Files from Directory [C#][^]
Try and post specific issue if you get stuck.
使用Directory
classGetFiles
函数.
UseDirectory
classGetFiles
function.
string path=@"c:\";
string[] files = System.IO.Directory.GetFiles(path);
// ...
之后,将文件集合绑定到Gridview.
After that bind the files collection to Gridview.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Files_Folder;
using System.IO;
using System.Data;
namespace WriteListFileFolder
{
class Program
{
static void Main(string[] args)
{
DataTable DtTblList;
DtTblList = new DataTable();
DtTblList.Columns.Add("SrNo", typeof(int));
DtTblList.Columns.Add("EntryType", typeof(int));
DtTblList.Columns.Add("Path", typeof(string));
GetFileFolders(ref DtTblList, "D:\\GSDIntegration");
DtTblList.WriteXml("D\\XmlFile.xml");
}
static void GetFileFolders(ref DataTable DtTblList, string FolderPath)
{
string[] ListDirectory = Directory.GetDirectories( FolderPath);
if (ListDirectory.Length > 0)
{
for (int n = 0; n < ListDirectory.Length; n++)
{
DataRow _D = DtTblList.NewRow();
_D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 1;
_D["Path"] = ListDirectory[n]; DtTblList.Rows.Add(_D);
GetFileFolders(ref DtTblList, ListDirectory[n]);
}
}
else
{
string[] ListOfFiles = Directory.GetFiles(FolderPath);
for (int i = 0; i < ListOfFiles.Length; i++)
{
DataRow _D = DtTblList.NewRow();
_D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 2;
_D["Path"] = ListOfFiles[i]; DtTblList.Rows.Add(_D);
}
}
}
}
}
这篇关于显示位于文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文