# Creating Web Directory/folder dynamically with ASP.NET



## OscarTT21 (Dec 11, 2008)

Hi there,

I need to let a site user create their own directory on the server which they will name and the content of which will hold a mini site for them to customise as they please.
So when the user creates this directory it needs to have a set of pages within that directory for example index,gallery,contact etc. these pages will be the same for every user and the content for each stored on the MySQL database.

I have done some research and it seems that (if you are in the know) that it is a pretty simple task in ASP.NET to dynamically create a folder but i have not yet got it to work cos I'm so uneducated with ASP.NET.

Couple of things;
I'm not developing directly on a server as I'm using shared hosting for now but i do have most privileges except remote access.
My prime development language is classic ASP so if there is a classic asp solution this would suit me better 
Fingers crossed
Cheers
Oscar


----------



## OscarTT21 (Dec 11, 2008)

I have managed to do this with classic asp which i should have searched before to be honest but now i need to know how to save the set of webpages to this folder as soon as the folder is created.

This is what i used to create the folder;

```
<%
newfolder = replace(request.form("sitename"), "'", "''")
Dim objFSO 
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
'Create the folder 
If Not objFSO.FolderExists("D:\mysite.co.uk\httpdocs\dog-breeders\" & newfolder) then 
 objFSO.CreateFolder("D:\mysite.co.uk\httpdocs\dog-breeders\" & newfolder) 
End If 
%>
```


----------



## OscarTT21 (Dec 11, 2008)

Look like this one is sorted. A bit more searching and i managed to create this script in classic asp to dynamically create the folder and then add an existing set of web pages on the sever to the new folder.

```
<%@ Language=VBScript %>
<%
chosenfolder = replace(request.form("sitename"), "'", "''")
Dim objFSO 
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
'Create the folder if it doesnt already exist
If Not objFSO.FolderExists("D:\mysite.co.uk\httpdocs\dog-breeders\" & chosenfolder) then 
 objFSO.CreateFolder("D:\mysite.co.uk\httpdocs\dog-breeders\" & chosenfolder) 
Else
 set objFSO = Nothing
 response.redirect("index.asp?message=The folder name you chose already exists please type a different folder name and try again")
End If
Const HoldingFolder = "D:\mysite.co.uk\httpdocs\dog-breeders\pageset"  
NewFolder = "D:\mysite.co.uk\httpdocs\dog-breeders\" & chosenfolder & "" 
 
Dim objFSO2, objHoldingFolder, objFile  
Set objFSO2 = CreateObject("Scripting.FileSystemObject")  
Set objHoldingFolder = objFSO2.GetFolder(HoldingFolder)  
 
  For Each objFile In objHoldingFolder.Files  
   objFile.Copy NewFolder & "\" & objFile.Name  
  Next
set objFSO = Nothing
Set objFSO2 = Nothing
Set objHoldingFolder = Nothing
response.redirect("" & chosenfolder & "/index.asp")
%>
```


----------

