简体   繁体   中英

how to access all filenames from a remote server folder - c#?

I have many images on remote server say images.foo.com/222 & i want to access file names of all files that resides in the folder 222 on images.foo.com/. i have tried following code but getting error "virtual path is not valid" :

imageserver = http://images.foo.com/222;
DirectoryInfo di = new DirectoryInfo(imageserver); // line giving exception
FileInfo[] rgFiles = di.GetFiles();
string simagename = ""; 
if (rgFiles.Count() > 0)
{
foreach (FileInfo fi in rgFiles)
{
//collect each filename from here
}
}

Please help thanks in advance gbaxi

DirectoryInfo need a UNC path of type "\\\\fileserver\\images"

A http address will not work

You can't access a directory residing on the web with the DirectoryInfo class. Instead, use the WebRequest class to get a list from the URL and get the files from that list.

The problem is that HTTP does not have a clear interface on how a directory listing is being displayed. There are roughly two choices:

  1. Parse the HTML retrieved through a WebRequest, but you won't get things like creation/modification time and user;

  2. Go with a different mechanism to retrieve the file details like FTP or File share.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM