如何在Asp.net中创建动态目录并在网页上显示? [英] How To create Dynamic Directory in Asp.net and Display On Webpage ?
问题描述
你好早安!
我有一个要求,我需要在我的网站上创建目录和显示
那我怎么能这样做...
例如:
我在文本框中输入目录名称,当我点击在按钮上它应该是在网页上创建。
在此先感谢。 :)
1.首先,您应该使用应用程序中的文件夹作为所有文件夹的父文件夹,假设此文件夹名为内容
。
2.然后,如果您还想让用户下载/访问此文件夹,您应该设置您的应用程序中的一些访问权限web.config
,如下例所示:
< location 路径 = 内容 >
< system.web >
< 授权 >
< allow users = * / >
< / authorization >
< / system.web >
< / location >
3.最后,您应该使用C#代码创建文件夹,如下例所示:
< pre lang =cs> string newPath = Server.MapPath( string .Format( 〜/ Content / {0},folderNameWithoutPath ));
DirectoryInfo directoryInfo = new DirectoryInfo(newPath);
if (!directoryInfo.Exists)
{
directoryInfo.Create();
}
参考 - 使用C#和VB.Net在ASP.Net中创建和删除文件夹(目录) [ ^ ]
要显示目录,需要使用TreeView控件。请参阅文章。
1. 使用ASP.NET TreeView控件显示目录和文件 [ ^ ]
2. 使用ASP.NET中的TreeView控件显示目录结构 [ ^ ]
Hello Good Morning !
I have One Requirement that i need to create Directory and Display on my website
So how can i do that ...
For example:
I enter Directory name in Textbox and when i click on button it should be Create on Webpage.
Thanks In Advance. :)
1.First you should use a folder from your application as parent folder of all your folders, lets suppose that this folder will be namedContent
.
2.Then if you want also to give the user possibilities to download/have access to this folder you should set up some access rights in your applicationweb.config
like in the next example:
<location path="Content"> <system.web> <authorization> <allow users="*" /> </authorization> </system.web> </location>
3.Finally you should use C# code to create the folder like in the next example:
string newPath = Server.MapPath(string.Format("~/Content/{0}", folderNameWithoutPath)); DirectoryInfo directoryInfo= new DirectoryInfo(newPath); if (!directoryInfo.Exists) { directoryInfo.Create(); }
Refer - Create and delete folder (directory) in ASP.Net using C# and VB.Net[^]
To show the directories, you need to use TreeView control. See the articles.
1. Using the ASP.NET TreeView control to display directories and files[^]
2. Display Directory Structure Using TreeView Control in ASP.NET[^]
这篇关于如何在Asp.net中创建动态目录并在网页上显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!