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...
精彩评论