Forum Moderators: open

Message Too Old, No Replies

How to create a folder by using ASP

         

anicesoul

7:41 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



Dear everyone,
I don't know that my topic is on the right forum or not, if it's not please feel free to move it and let me know.
I am creating a site, which allow users to create a folder, using ASP.
This is the code i have:

<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
fs.CreateFolder("c:\test1")
set fs = nothing
%>

My questions are:
What Server object relates to? is that my server or is that a syntax which i have to type in exactly?
After i wrote this code and run, i couldn't find the folder location
i don't really know that it is created or not.
Anyone know about ASP please tell me more about this. it's just two line of code
but it 's relate more with webserver.
Thank alot everyone

Iguana

8:45 pm on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Server is the ASP Server object - that is your IIS webserver. You are accessing this through a web page therefore the security context is <machinename>_user or something like that. This is a low security Windows account (not allowed to do much on your PC) so it can't create directories unless you have specifically allowed it to do so. You really don't want anonymous web user to be able to have conrol over your disk!

You could allow this Windows user account some control over a specified directory so that it could create directories and files - but watch out because if a hacker sees this is allowed they will try and breach your security because they know they will have control to upload files and if they exploit any security holes they could run EXEs they uploaded to that directory.

anicesoul

2:57 pm on Aug 13, 2005 (gmt 0)

10+ Year Member



Dear Iguana,
Thank you for your reply.
I am just a newbie for this kind of stuff, so then i don't really know which way is be good way to do.
The thing i am working on is just a better way to create an intranet site for my own server, so then i can create some pictures folder on my server, like Yahoo Photos. And then i can upload my pics into that specific folder.
I took a look all day for "create folder using ASP". But i still don't understand how exactly it works by that 2 lines of code.
If you can give me little more detail step by step for a dummie like me to understand. That will be very great, i appreciate.
Thank again

mrMister

4:52 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Set fs = Server.CreateObject("Scripting.FileSystemObject")

Here you create an instance of the FileSystem COM Object I believe this COM object comes with VBScript which is installed on Windows as standard). You name the instance fs (short for filesystem) (

fs.CreateFolder("c:\test1")

Here you call a method of the filesystem COM object called CreateFolder which does exactly what it says on the tin.

set fs = nothing

Here you set your instance of the object to Nothing (which frees up the memory on your server)

What you're doing is calling a COM object, executing it's method, and the COM object takes over from there, executing all the complex code that deals with the filesystem. That's the beauty of Object Oriented programming, you can use an object without knowing how it works.

If you would like to learn more about the File System COM object, the documentation is here...

[msdn.microsoft.com...]

anicesoul

4:28 am on Aug 16, 2005 (gmt 0)

10+ Year Member



Thank you mrMister,
Your explaination is very clear and easy to understand.
My next question is that where is the folder?
is it located in c:\ drive?
or server drive?
Actually i tried the code many time, but i couldn't find the folder, no way i can test it.
One more question. If i want to create a folder in some special file such as \\pictures\may2005 which is one of path to another drive in my server.
HOw do i make a path. And how do i link it to the specific drive in the server.

MrAbeBS

8:24 pm on Aug 23, 2005 (gmt 0)



anicesoul-
The folder is actually located on your webserver... your server's directory structure will determine where the files that are available to the web actually "physically" exist...

Luckily, there is a very simple way to extract this data:

I would create a variable which contains the Physical File Path, followed by the name of the folder you wish to create, for instance:

FilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "pictures\"

Request.ServerVariables("APPL_PHYSICAL_PATH") returns the exact path of your web files... try doing a Response.Write Request.ServerVariables("APPL_PHYSICAL_PATH") and you'll see what I mean...

hope this helps, best of luck!