ASP.NET - Uploading Folder in Asp.Net - Asked By Hema Moss on 10-Mar-09 03:53 AM
I want to upload a folder in asp.net application. If i use FileUpload control, it allows me to select only 1 file. But i want to upload whole folder at once, is it possible to do...?
Uploading Folder with ASP.NET - mv ark replied to Hema Moss on 10-Mar-09 04:09 AM
It is not possible to upload an entire folder. You may have to zip the files in the folder to upload everything at once or use a multiple file upload control like this one - http://www.codeproject.com/KB/aspnet/FlashUpload.aspx
Alternatively you can adapt this jQuery plugin -
How to upload multiple Files in ASP.net - Kalit Sikka replied to Hema Moss on 10-Mar-09 04:22 AM
Use the ‘HttpFileCollection’ class to retrieve all the files that are uploaded. Files are encoded and transmitted in the content body using multipart MIME format with an HTTP Content-Type header. ASP.NET extracts this information from the content body into individual members of an HttpFileCollection.
The code would look as follows:
protected void btnUpload_Click(object sender, EventArgs e)
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
hpf.SaveAs(Server.MapPath("MyFiles") + "\\" +
catch (Exception ex)
// Handle your exception here
re - Web Star replied to Hema Moss on 10-Mar-09 04:46 AM
this is not possible directly to upload all file from folder because the FileUpload control select a file at a time
so if u want like that then u need to do different way means u can give the option for selecting more than one file, or u can do this is window services like Picasa.google.com etc.
New Approach - Asked By Hema Moss on 12-Mar-09 01:19 AM
Thanks for ur replies. I have approached a different way to Upload Folder by using DirectoryInfo().... its working fine. But here i have one problem, this application is deployed in the remote server(Windows 2003). When im trying to upload folder from the development site, its working fine. When i upload it from my machine, its not allowing me to upload. I think there is some credentials problem.... but how can i solve this.... below is my code.....
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(txtFolderPath.Text));
foreach (FileInfo file in dirInfo.GetFiles())
string strFilePath = file.FullName;
string strFileName = file.Name;
StreamReader tempStream = file.OpenText();
Stream fStream = tempStream.BaseStream;
byte contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
Can anyone help me with this...?
My name is Naveed - Naveed Khan replied to Hema Moss on 30-Jun-09 12:46 AM