来自URL的Directoryinfo [英] Directoryinfo from URL
问题描述
大家好,
我有一个TreeView来列出目录的内容。目录/文件夹位于托管网站的同一服务器上。它工作得很好。
我正在尝试从外部URL列出目录的内容。
我尝试了很多方法而且都给出了错误
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
这是有意义的。
我想知道列出URL文件夹 内容的最佳方法是什么 。如果不可能有替代解决方案吗?
我正在使用asp.net webforms。
提前付款
Samira
我的尝试:
我的代码浏览网络服务器上的文件夹:
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
with
DirectoryInfo rootInfo = new DirectoryInfo(@"https://abc/f1/webApp/apps");
推荐答案
\f1\webApp\apps);
int directoryCount = rootInfo.GetDirectories()。Length;
Docs_treeView.Nodes.Clear();
//如果在所选目录下有sub-direcotries列出
if(directoryCount> ; 0)
{
this.PopulateTreeView_WithDirectories(rootInfo,Docs_treeView,null);
}
else
{
//只填充文件
this.PopulateTreeView_WithFiles(rootInfo,Docs_treeView,null);
}
\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);
\f1\webApp\apps");
with
with
DirectoryInfo rootInfo = new DirectoryInfo(@"https://abc/f1/webApp/apps");
不可以,因为服务器不公开其文件结构。 IIS中曾经有一个设置(可能仍然是)以允许列出目录内容,但默认情况下它不会启用安全设置。
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.
这篇关于来自URL的Directoryinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!