开发者

how to get list of files in the server using C# not using ASP.net

开发者 https://www.devze.com 2023-01-29 07:35 出处:网络
Am downloading a setup file from server, name of the setup file varies for each version sobefore downloadi开发者_如何学Pythonng it i need to get the file nameSomething similar to:

Am downloading a setup file from server, name of the setup file varies for each version so before downloadi开发者_如何学Pythonng it i need to get the file name


Something similar to:

void Page_Load(object s, EventArgs e)
{
 DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
 FileInfo[] rgFiles = di.GetFiles("*.aspx");
 foreach(FileInfo fi in rgFiles)
 {
  Response.Write("<br><a href=" + fi.Name + ">" + fi.Name + "</a>");       
 }
}

DirectoryInfo:
http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx

OR

Retrieving a List of Files from an FTP server in C#


I am not 100% sure what you are asking here, but if you want to get a list of all the files on the server using something along the lines of:-

string[] files = 
Directory.GetFiles
  (@"c:\myfolder\", "*.exe", SearchOption.TopDirectoryOnly); 

or using linq

var files = from f in Directory.GetFiles(@"c:\myfolder\")
    where f.Contains(".exe")
    select f;

Once you get all the files then you need to iterate through the results and work out which one you want to return.

We probably need more info...

0

精彩评论

暂无评论...
验证码 换一张
取 消