How to create a folder on button click?http://forums.asp.net/t/1366226.aspx/1?How+to+create+a+folder+on+button+click+Tue, 03 Mar 2009 15:17:25 -050013662262839494http://forums.asp.net/p/1366226/2839494.aspx/1?How+to+create+a+folder+on+button+click+How to create a folder on button click? <p>&nbsp;Hi All,</p> <p>&nbsp;I am trying to create directories in a particular folder.It is like this &quot;It is like this, A textbox and a button will be present in the page. Once I click the button A folder should be created with the name present in the textbox&quot; Can anyone let me know &quot;How do I achieve this&quot;?</p> <p>&nbsp;</p> <p>Thanks and Regards</p> <p>&nbsp;Sandeep. <br> </p> 2008-12-31T06:45:15-05:002839520http://forums.asp.net/p/1366226/2839520.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Try with this:</p> <blockquote><span class="icon-blockquote"></span>&nbsp;&nbsp;&nbsp; protected void Button1_Click(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IO.Directory.CreateDirectory(MapPath(&quot;~/&quot; &#43; TextBox1.Text));<br> &nbsp;&nbsp;&nbsp; }</blockquote> <p></p> 2008-12-31T07:01:00-05:002839523http://forums.asp.net/p/1366226/2839523.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Use Directory.Create method</p> 2008-12-31T07:02:15-05:002839524http://forums.asp.net/p/1366226/2839524.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Here is the code:</p> <font size="2"> <p>System.IO.</font><font color="#008080" size="2">Directory</font><font size="2">.CreateDirectory(TextBox1.Text);</font></p> <p><font size="2">&nbsp;</p> </font> 2008-12-31T07:03:50-05:002839574http://forums.asp.net/p/1366226/2839574.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>&nbsp;Try this code:-</p> <p>&nbsp;</p> <p>System.IO.Directory.CreateDirectory(MapPath(&quot;~/&quot; &#43; TextBox1.Text)); <br> </p> 2008-12-31T07:42:19-05:002839592http://forums.asp.net/p/1366226/2839592.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p></p> <blockquote><span class="icon-blockquote"></span> <h4>sirdneo</h4> <p>&nbsp;Try this code:-</p> <p>&nbsp;</p> <p>System.IO.Directory.CreateDirectory(MapPath(&quot;~/&quot; &#43; TextBox1.Text)); <br> </p> </blockquote> WOW, great! I wonder how I and sandeepbhutani304 didn't think of that? [^o)] 2008-12-31T07:52:54-05:002839605http://forums.asp.net/p/1366226/2839605.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>&nbsp;Thank you, it resolved the issue. </p> <p>Hey, can you help me on more issue?&nbsp;</p> <p>This is the situation. I have so many folders in my project. I need to upload files to different folders. How would I get an option to select a particular folder to save the file at run time?&nbsp;</p> <p>&nbsp;</p> <p>Sandeep <br> </p> 2008-12-31T08:02:06-05:002839626http://forums.asp.net/p/1366226/2839626.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>You can use RadioButtonList which you can Bind with list of your Directories:<br> Control:</p> <blockquote><span class="icon-blockquote"></span>&lt;asp:RadioButtonList ID=&quot;RadioButtonList1&quot; runat=&quot;server&quot; RepeatColumns=&quot;5&quot; /&gt;</blockquote> Code (Page_Load event) - instead of &quot;*&quot;, you can use some search pattern: <blockquote><span class="icon-blockquote"></span>using System.IO;<br> <br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!IsPostBack)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DirectoryInfo dirInfo = new DirectoryInfo(MapPath(&quot;~/&quot;));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = dirInfo.GetDirectories(&quot;*&quot;, SearchOption.AllDirectories);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataBind();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</blockquote> Use this for Directory name when saving file: <blockquote><span class="icon-blockquote"></span>RadioButtonList1.SelectedItem.Text</blockquote> <p></p> 2008-12-31T08:10:49-05:002839822http://forums.asp.net/p/1366226/2839822.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Hey thank you very much for your quick reply. That has helped me a lot. Could you please let me know &quot;How to exclude particular folders from the radio button list&quot;?</p> <p>&nbsp;</p> 2008-12-31T10:17:37-05:002842113http://forums.asp.net/p/1366226/2842113.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Hi, </p> <p>&nbsp;Could you please let me know &quot;How would I disable radio button list item for a particular folder&quot;&nbsp; <br> </p> 2009-01-02T05:07:10-05:002842210http://forums.asp.net/p/1366226/2842210.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Here is an example where will&nbsp;folders listed in &quot;excludedDirs&quot; be excluded in the RadioButtonList. But keep in mind that this is a Linq example and will work only in ASP.NET 3.5, so if you're using ASP.NET 2.0, let me know.<br> </p> <blockquote><span class="icon-blockquote"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DirectoryInfo dirInfo = new DirectoryInfo(MapPath(&quot;~/&quot;));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] excludedDirs = { &quot;App_Code&quot;, &quot;App_Data&quot;, &quot;App_GlobalResources&quot;, &quot;App_LocalResources&quot; };<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = from p in dirInfo.GetDirectories(&quot;*&quot;, SearchOption.AllDirectories)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where !excludedDirs.Contains(p.Name)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select p;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataBind();</blockquote> <p></p> 2009-01-02T06:20:19-05:002842219http://forums.asp.net/p/1366226/2842219.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Yes, I am using .Net 2.0 Frame work. And I kindly request you to get me the code in VB.Net<br> </p> <p>&nbsp;</p> <p>Thanks and Regards&nbsp;</p> <p>Sandeep <br> </p> 2009-01-02T06:27:39-05:002842253http://forums.asp.net/p/1366226/2842253.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Here it is:</p> <blockquote><span class="icon-blockquote"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not IsPostBack Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dirInfo As DirectoryInfo = New DirectoryInfo(MapPath(&quot;~/&quot;))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim excludedDirs As String() = {&quot;App_Code&quot;, &quot;App_Data&quot;, &quot;App_GlobalResources&quot;, &quot;App_LocalResources&quot;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = dirInfo.GetDirectories(&quot;*&quot;, SearchOption.AllDirectories)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataBind()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i As Integer = RadioButtonList1.Items.Count - 1 To 0 Step -1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each excludedDir As String In excludedDirs<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If RadioButtonList1.Items(i).Text = excludedDir Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.Items.RemoveAt(i)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</blockquote> <p></p> 2009-01-02T06:55:38-05:002842311http://forums.asp.net/p/1366226/2842311.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>&nbsp;Thank you very much kipo, you are really great!!! You have helped me a lot to resolve the issue. </p> <p>&nbsp;Thanks and Regards</p> <p>&nbsp;Sandeep <br> </p> 2009-01-02T07:33:19-05:002842487http://forums.asp.net/p/1366226/2842487.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>&nbsp;Hi Kipo, </p> <p>I am getting a small error message for the above code. If I have started including so many folders &quot;I am getting an error message saying <br> </p> <h2><i>&quot;Index was out of range. Must be non-negative and less than the size of the collection.<br> Parameter name: index</i>&quot; </h2> <p>Could you please let me know &quot;Where do I need to change the code&quot; to get the issue fixed.</p> <p>&nbsp;Thanks and Regards</p> <p>Sandeep&nbsp; <br> </p> 2009-01-02T09:41:05-05:002842491http://forums.asp.net/p/1366226/2842491.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>On what line of the code you get that error?</p> 2009-01-02T09:43:31-05:002844096http://forums.asp.net/p/1366226/2844096.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>I am getting an error message at this point of code : &quot;If RadioButtonList1.Items(i).Text = excludedDir Then&quot;</p> <p>Please recheck with this and let me know.</p> <p>&nbsp;Thanks and Regards</p> <p>Sandeep&nbsp; <br> </p> 2009-01-03T06:17:21-05:002844325http://forums.asp.net/p/1366226/2844325.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Can you post whole code you used?</p> 2009-01-03T10:01:14-05:002846392http://forums.asp.net/p/1366226/2846392.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>&nbsp;Yes, Here is the Code that I have used </p> <p>If Not IsPostBack Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dirInfo As DirectoryInfo = New DirectoryInfo(MapPath(&quot;~/&quot;))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim excludedDirs As String() = {&quot;App_Code&quot;, &quot;App_Data&quot;, &quot;App_GlobalResources&quot;, &quot;App_LocalResources&quot;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = dirInfo.GetDirectories(&quot;*&quot;, SearchOption.AllDirectories)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataBind()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i As Integer = RadioButtonList1.Items.Count - 1 To 0 Step -1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each excludedDir As String In excludedDirs<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If RadioButtonList1.Items(i).Text = excludedDir Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.Items.RemoveAt(i)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If </p> <p>&nbsp;</p> <p>When I am adding more directories over here &quot;Dim excludedDirs As String() = {&quot;App_Code&quot;, &quot;App_Data&quot;, &quot;App_GlobalResources&quot;, &quot;App_LocalResources&quot;}&quot; I am getting an error message at this place &quot; If RadioButtonList1.Items(i).Text = excludedDir Then&quot;. Please check with this and help me.</p> <p>&nbsp;Thanks and Regards</p> <p>&nbsp;Sandeep.</p> <p>&nbsp;</p> 2009-01-05T03:30:32-05:002846753http://forums.asp.net/p/1366226/2846753.aspx/1?Re+How+to+create+a+folder+on+button+click+Re: How to create a folder on button click? <p>Try with this:</p> <blockquote><span class="icon-blockquote"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not IsPostBack Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dirInfo As DirectoryInfo = New DirectoryInfo(MapPath(&quot;~/&quot;))<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim excludedDirs As String() = {&quot;App_Code&quot;, &quot;App_Data&quot;, &quot;App_GlobalResources&quot;, &quot;App_LocalResources&quot;}<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = dirInfo.GetDirectories(&quot;*&quot;, SearchOption.AllDirectories)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.DataBind()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i As Integer = RadioButtonList1.Items.Count - 1 To 0 Step -1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each excludedDir As String In excludedDirs<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If RadioButtonList1.Items(i).Text = excludedDir Then<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RadioButtonList1.Items.RemoveAt(i)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>Exit For</strong><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</blockquote> <p></p> 2009-01-05T06:52:16-05:00