By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

How to create a file folder dynamically .

P: 3
hello All ,

I am using the below given code to create a folder on a click event from a button.

The Folder name should be a string which i am taking it from the text box value.


now my problem is am not able to figure out how i can create a folder with the input text box value name.


<%@LANGUAGE="VBSCRIPT"%>

<%
Option Explicit
CreateFolder(Server.MapPath("."+ "test"))
Dim objFso
'# CREATE FOLDER
function CreateFolder(fdirCRE)
Set objFso = CreateObject("Scripting.FileSystemObject")
if Not objFso.FolderExists(fdirCRE) Then
objFso.CreateFolder(fdirCRE)
Else
Exit function
End if
Set objFso = nothing
End function




%>
<html>
<input type="button" ID="buttonCreateFolder" value="Create Folder" OnClick="CreateFolder()" />

</html>
Jan 9 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 164
OnClick is not a feature of VBScript. Maybe for a ASP.NET html control, but not regular ol' ASP. To get this to work, you will actually have to submit a form. Inside the form will have to be a text box. The user will have to type something into the text box, then submit the form.

ASP VBScript will then pick up the value through Request.Form.

My quick solution below is meant to be illustrative. Change the ACTION attribute on the form to the filename of your script.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. '// if the user submitted the form
  3.  
  4. if request.form("folder_name") <> "" then
  5.    ' 
  6.    ' you might want to validate folder name is legal
  7.    ' by Operating System standards...
  8.    '
  9.    set objFSO = server.createobject("scripting.filesystemobject")
  10.    folderName = request.form("folder_name")
  11.    absFolderPath = server.mappath("/") & "/" & folderName
  12.  
  13.    if not objFSO.FolderExists(absFolderPath) then
  14.       objFSO.createfolder absFolderPath
  15.    end if
  16. %>
  17.  
  18. <html>
  19.    <body>
  20.       <form method="post">
  21.          <input type="text" name="folder_name" />
  22.       </form>
  23.    </body>
  24. </html>
  25.  
Jan 9 '08 #2

P: 1
public void Createnewfolder()
{
string str = Session["UrlUserId"].ToString();


DirectoryInfo dir = null;

dir = new DirectoryInfo(Server.MapPath("~/Profile") + "/" + str);

if (!dir.Exists)
{

dir.Create();
}

}
Jan 15 '08 #3

P: 1
public void Createnewfolder()
{
string str = Session["UrlUserId"].ToString();


DirectoryInfo dir = null;

dir = new DirectoryInfo(Server.MapPath("~/Profile") + "/" + str);

if (!dir.Exists)
{

dir.Create();
}

}

sir this is worknig fine. but i want give a foldername in textbox that name should be given for the folder.afetr that all folder name display in dropdown list. i select the folder name in dropdown list and upload the file for particular folder.pl send code to me.
Mar 14 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.