我需要在文件夹中列出所有文件(包括.doc,.pdf,.txt等),并能够使用jquery / asp.net c#下载和删除该文件。
答案 0 :(得分:1)
我不确定ASP.Net是否支持它,但Directory.GetFiles
应该可以正常工作以获取目录中的所有文件。如果需要在子目录中添加对文件的支持,可以使该方法递归。
答案 1 :(得分:1)
string[] filePaths = Directory.GetFiles(pathname, "*.sql",
SearchOption.TopDirectoryOnly);
TopDirectoryOnly不包含子目录。
for (int i=0; i<filePaths.Length; ++i)
listtBox1.Items.Add(filePaths[i]);
从此列表框中,您可以删除文件或将文件移动到另一个文件夹。
答案 2 :(得分:0)
string filephysicalpath=""; //Specify Physical path of file
string filevirtualpath =""; //Specify Virtual path of file
DirectoryInfo d = new DirectoryInfo(filephysicalpath);
FileInfo[] Files = d.GetFiles("*" + filematch + "*.pdf");
string strFilename="";
foreach (FileInfo file in Files)
{
strFilename=filevirtualpath + "/" file.Name; // This will give you the full hosted path of file with name loopwise.. so that you can download it directly by clicking the link.
}
//For Deleting file using Jquery my suggestion is write delete code in web service or in another code page and call it using Ajax
答案 3 :(得分:0)
string[] fileEntries = Directory.GetFiles(targetDirectory);