Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have a TreeView to List contents of a directory. The directory/folder locates on the same server the website is hosted. It is working very well.
I'm trying to list the contents of a directory from external URL.
I have tried many ways and all gives error
URI formats are not supported
which makes sense.
I want to know what is the best way to list contents of URL folder if possible. If not possible is there an alternative solution?
I'm using asp.net webforms.

Thanks in advance
Samira

What I have tried:

My code to browse folder on the webserver:
DirectoryInfo rootInfo = new DirectoryInfo(@"\\10.0.0.8\d$\f1\webApp\apps");
            int directoryCount = rootInfo.GetDirectories().Length;
            Docs_treeView.Nodes.Clear();
            //if there's sub-direcotries under the selected directory to list
            if (directoryCount > 0)
            {
                this.PopulateTreeView_WithDirectories(rootInfo, Docs_treeView, null);
            }
            else
            {
                //just populate only files 
                this.PopulateTreeView_WithFiles(rootInfo, Docs_treeView, null);
            }

Trying to replace
DirectoryInfo rootInfo = new DirectoryInfo(@"\\10.0.0.8\d$\f1\webApp\apps");

with
DirectoryInfo rootInfo = new DirectoryInfo(@"https://abc/f1/webApp/apps");
Posted
Updated 16-May-17 4:34am
v2

No, it is not possible because servers do not expose their file structure. There used to be a setting (and may still be) in IIS to allow listing of directory contents but it is not on by default for security settings.
 
Share this answer
 
Hello,

I expect you doing this from the server. Then you need to map URL to the physical path:
HttpServerUtility.MapPath Method (String) (System.Web)[^]

If you are not doing this from the server, there's no way to do this. As Ryan said, servers do not expose their file structure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900