Creating Directories in ASP

MoMo
07-14-2002, 05:27 PM
Does anyone know if it's possible to create directories via ASP? I've looked at the file system object, but it only seems to display contents and allow files to be copied. What I need is a way to copy files as well as create directories thru ASP. If this is not possible, are there any 3rd party components that would do this? Thanks in advance.

Thinker
07-14-2002, 05:48 PM
That is what the FileSystemObject (and the whole Microsoft
Scripting Runtime) was originally created for. It can be used to
create, copy, move and delete directories and files.

Dim FSO, Fldr
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fldr = FSO.CreateFolder("C:\FSOTest") 'Create Directory
Fldr.Move "C:\FSOTest1" 'Rename Directory
Fldr.Delete True 'Delete Folder
Set Fldr = Nothing
Set FSO = Nothing

MoMo
07-14-2002, 06:13 PM
That did the trick. Thanks a bunch. The tutorial I was reading on the FSO left that part of it out.

It seems now, however, that i'm unable to copy files to the newly created directory because of the permissions. Is there a way to set the permissions on the directory so that IUSR_Machine has Read and Write? Thanks again.

Here's the code i'm using:

<%
Dim objFSO, strFolder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Set strFolder = objFSO.CreateFolder(Server.MapPath("New Account"))

objFSO.CopyFile Server.MapPath("admin.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("index.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("login.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("login_check.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("login_request.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("page.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("process_admin_update.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("process_login_request.asp"), Server.MapPath("New Account/")
objFSO.CopyFile Server.MapPath("contact.asp"), Server.MapPath("New Account/")

Set strFolder = Nothing
Set objFSO = Nothing
%>

Derek Stone
07-14-2002, 06:15 PM
You'll also need to make sure that the files and directories have the proper permissions set for the IIS user account (IUSR_<compname>). If you're using a shared host you'll need to contact them and request such changes.

-CL

Thinker
07-14-2002, 06:27 PM
It does seem strange that you would have permissions to create
a folder, but then not have permissions to read and write to the
folder. The owner of the folder should be the user under whose
security context it was created. I would assume the owner would
have read and write permissions. This just goes to show how
little I understand about IIS/Windows security.

MoMo
07-14-2002, 07:11 PM
Thanks for the replies. :)

After giving the main site directory IUSR_<machinename> Read and Write permissions, I was still getting permission denied errors. Come to find out that Server.MapPath doesn't include the backslash, even if you put it in.....to get around this I had to include & "\" after Server.MapPath. So if anyone has a need to do something similar, set your appropriate permissions and see the code below for reference. This snippet of code worked fine for me.


<%
Dim objFSO, strFolder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set strFolder = objFSO.CreateFolder(Server.MapPath("New Account"))
Set strFolder = objFSO.CreateFOlder(Server.MapPath("New Account\images"))

objFSO.CopyFile Server.MapPath("admin.asp"), Server.MapPath("New Account") & "\", True
objFSO.CopyFile Server.MapPath("image1.jpg"), Server.MapPath("New Account\images") & "\", True

Set strFolder = Nothing
Set objFSO = Nothing

Response.Redirect "success.asp"
%>


One thing to note, by giving IUSR Read/Write permissions, you allow anyone to write to the directory, which of course creates a nice little security hole. I'm gonna do some more searching to see if there is another method I can use to accomplish the same tasks. I was hoping to find something that would let me set permissions through code, meaning set IUSR to read/write before i copy and then remove read/write after i'm done copying. Anyhow, thanks for the help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum