Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create folder in code behind page
    primarykey
    data
    text
    <p>This is in reference to yesterday's question <a href="https://stackoverflow.com/questions/710123/how-do-i-create-folders-in-asp-net-in-code-behind">"How do I create folders in ASP.NET in code behind"</a>. The problem is that I want to create dynamic folders at run time. Folder names will be entered via a TextBox and output will be displayed in a TreeView. The form will submit if I enter the first folder name into textbox1 and click the "Add Folder" button. When I submit multiple folders with the same name, the output should be an indexed increment of the name (e.g., FooFolder, FooFolder(2), FooFolder(3), etc). There are two events: Add Folder Event and Remove Folder Event. If I select a particular child folder and click on the "Remove folder" button, the folder will be removed. For adding a folder I have written the following code:</p> <pre><code>TreeNode tnode = new TreeNode(); if (TreeView1.Nodes.Count &gt; 0) { int found = 0; for (int i = 0; i &lt; TreeView1.Nodes.Count; i++) { if (TreeView1.Nodes[i].Text == TextBox1.Text) found += 1+i; } if (found &gt; 0) { tnode.Text = TextBox1.Text + found.ToString(); } else { tnode.Text = TextBox1.Text; } } else { tnode.Text = TextBox1.Text; } TreeView1.Nodes.Add(tnode); } </code></pre> <p>In my code, the ChildNode index is not incrementing; it is always 1, like this:</p> <pre><code>Sumit Sumit(1) Sumit(1) Sumit(1) Amit Amit(5) Amit(5) Amit(5) </code></pre> <p>In the treeview, I have set <code>ImageSet="XPFileExplorer"</code>. So the output should look like this:</p> <pre><code>-Root -Sumit(Parent1) NewFolder NewFolder(2) NewFolder(3) NewFolder(4) NewFolder(5) -Amit(Parent2) FooFolder FooFolder(2) FooFolder(3) FooFolder(4) FooFolder(5) </code></pre> <p>If I delete any child folder, say, Newfolder(3) and Newfolder(4) and create these same folders under the same Sumit(Parent1), the index should be Newfolder(3),Newfolder(4). If I create one more NewFolder under Sumit with same name then the index should be NewFolder(6).</p> <p>Could somebody please modify my code to get this desired output?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload