开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜