列出文件夹中的所有文件

时间:2023-01-14 10:03:57

I need to list all the files(includes .doc, .pdf,.txt etc) in a folder and able to download and delete that file using jquery/asp.net c#.

我需要在文件夹中列出所有文件(包括.doc,.pdf,.txt等),并能够使用jquery / asp.net c#下载和删除该文件。

4 个解决方案

#1


1  

I'm not sure if it is supported on ASP.Net, but Directory.GetFiles should work fine to get all the files in a directory. If you need to add support for files inside subdirectories, you can make the method recursive.

我不确定ASP.Net是否支持它,但Directory.GetFiles应该可以正常工作以获取目录中的所有文件。如果需要在子目录中添加对文件的支持,可以使该方法递归。

#2


1  

string[] filePaths = Directory.GetFiles(pathname, "*.sql", 
SearchOption.TopDirectoryOnly);

TopDirectoryOnly does not include subdirectory.

TopDirectoryOnly不包含子目录。

for (int i=0; i<filePaths.Length; ++i)
     listtBox1.Items.Add(filePaths[i]);

And from this listbox, you can either delete or move your files to another folder.

从此列表框中,您可以删除文件或将文件移动到另一个文件夹。

#3


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

#4


0  

Directory.GetFiles:

Directory.GetFiles:

string[] fileEntries = Directory.GetFiles(targetDirectory);

#1


1  

I'm not sure if it is supported on ASP.Net, but Directory.GetFiles should work fine to get all the files in a directory. If you need to add support for files inside subdirectories, you can make the method recursive.

我不确定ASP.Net是否支持它,但Directory.GetFiles应该可以正常工作以获取目录中的所有文件。如果需要在子目录中添加对文件的支持,可以使该方法递归。

#2


1  

string[] filePaths = Directory.GetFiles(pathname, "*.sql", 
SearchOption.TopDirectoryOnly);

TopDirectoryOnly does not include subdirectory.

TopDirectoryOnly不包含子目录。

for (int i=0; i<filePaths.Length; ++i)
     listtBox1.Items.Add(filePaths[i]);

And from this listbox, you can either delete or move your files to another folder.

从此列表框中,您可以删除文件或将文件移动到另一个文件夹。

#3


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

#4


0  

Directory.GetFiles:

Directory.GetFiles:

string[] fileEntries = Directory.GetFiles(targetDirectory);