Make folders/subfolder on server

  • Thread starter Øyvind Isaksen
  • Start date
Ø

Øyvind Isaksen

I try to find som information about creating folders (and subfolders) on the
webserver using asp.net (1.0).
I have made a filuploader, and all files are now saved in the same folder on
the webserver. It had been smart if the users can make new directories in
this folder and save files in different folders/subfolders.

This is the code (example) I have used to upload the files to the server:
http://www.4guysfromrolla.com/webtech/091201-1.shtml

Hope anyone know how to create folders/subfolders using asp.net. Mabye some
code or a link to a tutorial or something would be fine :)

Thank you!!!
 
L

Laurent Bugnion

Hi,

Øyvind Isaksen said:
I try to find som information about creating folders (and subfolders) on the
webserver using asp.net (1.0).
I have made a filuploader, and all files are now saved in the same folder on
the webserver. It had been smart if the users can make new directories in
this folder and save files in different folders/subfolders.

This is the code (example) I have used to upload the files to the server:
http://www.4guysfromrolla.com/webtech/091201-1.shtml

Hope anyone know how to create folders/subfolders using asp.net. Mabye some
code or a link to a tutorial or something would be fine :)

Thank you!!!

You create a directory in ASP.NET just like you would in a WinForms
application, i.e. you use the System.IO namespace and the classes
Directory, DirectoryInfo, File, FileInfo.

The only different is that that IIS runs under a different username,
because it's a service, and thus has different rights. You must make
sure that the ASPNET user on the local machine has write rights on the
directory containing the subdirectories. But if you can upload a file
already, the user probably already has the corresponding rights.

Relative paths are also sometimes tricky on ASP.NET. The best is to
determine an absolute path (for example using the web.config file, you
can specify which folder is the parent directory (absolute path), and
then create the new folder's absolute path using its parent's absolute
path... if you get what I mean.

Example: How to create a session directory

String pathUpload = ConfigurationSettings.AppSettings[ "pathUpload" ];

// Prepare new directory for files
String newDirectory = Path.Combine( pathUpload, Session.SessionID );

// Check if directory exists and make sure we choose a unique path
if ( !Directory.Exists( newDirectory ) )
{
Directory.CreateDirectory( newDirectory );
}


Note that directories created this way must also be deleted! Thus you
must keep a trace of them in the session, for example, and use the
Session_End event to delete them.

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top