Hi experts, I have a problem with downloading file.
Okay, my project is setup in IIS (pointing to the folder in my desktop) and my users are able to login, upload a file into the folder.

However, they are not able to download the file (except me).
How can I do that?

Please help. The following is my codes for uploading and downloading

String projectID = (String)Session["projId"];
        //change the file name
        if (!FileUpload.FileName.Equals(""))
            // Create a new folder in Docs folder (folder name = projectID)
            System.IO.Directory.CreateDirectory(Server.MapPath("Docs/") + projectID + "/EP");

            // Save the file into the new folder.
            FileUpload.PostedFile.SaveAs(Server.MapPath("Docs/" + projectID + "/EP/" + FileUpload.FileName));
            lblFile.Text = FileUpload.FileName + " is uploaded!";
            lblFile.Visible = true;

DirectoryInfo diSource = new DirectoryInfo(Server.MapPath("Docs/" + pid + "/" + shortForm + "/"));
            string ExactFilename = string.Empty;

                foreach (FileInfo file in diSource.GetFiles(@"*.*"))
                    ExactFilename = file.FullName;

I understand that this is not "totally downloading a file".
I don't know the file format of each file my user has uploaded.

One way of doing it is to stream the file to the client. Here's a code C# snippet as an example:

private void StreamToClient(string filename, byte[] fileContent)
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("content-disposition", "attachment; filename=" + filename);


To pass in the bytes you could do:

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
StreamToClient("DownloadFileName.html", encoding.GetBytes(myFileContents));

That should get you going in the right direction.

Thanks for your prompt reply.
I will try that and get back to you if I have any questions. Is that all right?

This article has been dead for over six months. Start a new discussion instead.