0

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.

  • [Directory Class](http://msdn.microsoft.com/en-us/library/system.io.directory(v=vs.110).aspx) – EdSF Aug 03 '14 at 16:14
  • 1
    You cannot upload an entire folder with plain HTML / JavaScript. You could do a multiple file upload where the will `have` to select all the files and then type into a textbox the name of the folder. – Tasos K. Aug 03 '14 at 16:16
  • You can also checkout this link http://stackoverflow.com/questions/9618521/upload-contents-of-an-entire-folder-using-plupload – Tasos K. Aug 03 '14 at 16:18
  • @Tasos K. My aim is when i browse that folder all it files present in it should upload .Only files should upload not folder. – user3904186 Aug 03 '14 at 16:26

1 Answers1

1

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

Community
  • 1
  • 1
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62