i would like to list the files and folder on a remote web sever (http) using DirectoryInfo. I get an er开发者_如何学Cror when i do:
DirectoryInfo myDir = new DirectoryInfo(@"\\myservert\parantFolder\FilesFolder");
FileInfo[] dirFiles = myDir.GetFiles("*.txt");
What am i doing wrong. Would be grateful for every assistance.
Thanks
You're getting an error because DirectoryInfo is meant for use with the local file system or Windows File Shares (not shares over HTTP).
As a side not, the syntax you provide is not a share over HTTP. That syntax would look for a windows share on the myservert server in the FilesFolder subdirectory of the parantFolder share.
You would not be able to do it for a remote server over HTTP.
If you are using UNC path (like \\server) you need to make sure you have required permissions on that server and the folder.
UNC path refers to a shared server within network and not an HTTP server.
PS: You may consider using DirectoryInfo.GetFileSystemInfos this can list entire directory and sub-directories for you.
精彩评论