user3440940
user3440940

Reputation: 1

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 downloading it i need to get the file name

Upvotes: 0

Views: 1921

Answers (2)

Rippo
Rippo

Reputation: 22424

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...

Upvotes: 2

Greg McNulty
Greg McNulty

Reputation: 1466

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#

Upvotes: 2

Related Questions