user3904186
user3904186

Reputation: 13

To browse folder and Create folder in the server and upload files using asp.net

I am Currently working on asp.net i have worked on file upload by uploading files but i want browse a folder not a file and get all files in it and get foldername and create foldername in server and upload files it to server.Pls give me some refernce and help me to do this. My aim is when i browse that folder all it files present in it should upload .Only files should upload not folder Note:To browse folder not file.

Upvotes: 0

Views: 2375

Answers (1)

Manfred Radlwimmer
Manfred Radlwimmer

Reputation: 13394

Actually you are supposed to include a question if you want an answer, but it seems you are completely new to this so here are a few things you should know when it comes to asp.net and folder/file handling:

Your virtual path always corresponds to a local path on your webserver. Since it would be bad to hardcode that you might want to start off by mapping it. (e.g. /uploads/ to _C:\intepub\application\uploads)

"and get foldername"

string localpath = Server.MapPath("/uploads");

"and create foldername in server"

next you can check if that folder already exists, or if not - create it.

if(!System.IO.Directory.Exists(localpath))
    System.IO.Directory.Create(localpath))

Keep in Mind though that your IIS-User needs the rights to create new directories

Now that you have made sure that your upload directory exists, you can upload/download files. Here is a good tutorial to get started:

"and upload files it to server"

http://msdn.microsoft.com/en-us/library/aa479405.aspx

"but i want browse a folder not a file and get all files in"

You can do that on the server, not the client. Your asp.net code never executes on the client.

string[] filenames = System.IO.Directory.GetFiles(localpath);

"My aim is when i browse that folder all it files present in it should upload"

That one isn't so easy, sorry. It would pose a serious security risk to users.

Maybe this will point you in the right direction (apparently it works with Chrome)

How do I use Google Chrome 11's Upload Folder feature in my own code?

When it comes to files, directories, filepaths, etc. in general, I would recommend taking a closer look at these classes:

System.IO.File

System.IO.Directory

System.IO.Path

Upvotes: 1

Related Questions