1and1 Help Centre Categories

print article

Create a New Directory Using ASP.NET

In this article you will learn how to create a new directory using ASP.NET.

<%@ Import Namespace="System.IO"%>
<title>File Download</title>
<script language="VB" runat="server">
Sub createFolder(sender As Object, e As EventArgs)
If ((dirname.Text) = "") Then
message1.Text = "Error: you must enter directory name"
Directory.CreateDirectory(Server.MapPath("./" + dirname.Text))
message1.Text = "Directory successfully created"
End If
End Sub
<form runat="server">
<asp:Textbox id=dirname size=14 runat=server /><br/>
<asp:Button Text="Create Directory" OnClick="createFolder" Runat="Server"/><br/>
<asp:Label id="message1" Runat="Server"/><br/>
<asp:Label id="Folders" EnableViewState="False" Runat="Server"/><br/>

You have to change file/folder permissions using Webfiles to grant write permissions to the folder where the script is saved. Please make sure that both IUSR and NETWORK should have write permissions. You will also have to ensure the following line is present in your Web.Config file for this script to work:

<identity impersonate="true"/>
Please note:
The "CreateDirectory" method of ASP.Net needs a special right. This right is only available for the IUSR account. To make sure that your request is handled by the IUSR, you have to place the above line in Web.Config.
For additional information, you may want to reference: