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

//uploading
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;

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

            try
            {
                foreach (FileInfo file in diSource.GetFiles(@"*.*"))
                {
                    ExactFilename = file.FullName;
                    System.Diagnostics.Process.Start(ExactFilename);
                }
            }

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.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("content-disposition", "attachment; filename=" + filename);

        Response.BinaryWrite(fileContent);
        Response.End();
    }

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.