Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file in IIS?

I have written two methods such as FileUpLoad() and FileDownLoad() to Upload and Download a single file in my local system.

void FileUpLoad()
{
    string hfBrowsePath = fuplGridDocs.PostedFile.FileName; //fuplGridDocs is a fileupload control
    if (hfBrowsePath != string.Empty)
    {
        string destfile = string.Empty;            
        string FilePath = Path.Combine(@"E:\Documents\");            
        FileInfo FP = new FileInfo(hfBrowsePath);
        hfFileNameAutoGen.Value = PONumber + FP.Extension;
        destfile = FilePath + hfFileNameAutoGen.Value;   //hfFileNameAutoGen is a hidden field
        fuplGridDocs.PostedFile.SaveAs(destfile);
    }
}

void FileDownLoad(LinkButton lnkFileName)
{
    string filename = lnkFileName.Text;
    string FilePath = Path.Combine(@"E:\Documents", filename);
    fuplGridDocs.SaveAs(FilePath);
    FileInfo fileToDownLoad = new FileInfo(FilePath);

    if (fileToDownLoad.Exists)
    {
        Process.Start(fileToDownLoad.FullName);
    }
    else
    {
        lblMessage.Text = "File Not Saved!";
        return;
    }
}

While running the application before hosting it in IIS, I can upload a file to the desired location and can also retrieve a file from the saved location. But after publishing it in the localhost, I can only Upload a file. I could not download the saved file. There is no exception too. The Uploaded file is saved in the desired location. I don't know why it is not retrieving the file? Why I cant download the file in IIS? I have searched a lot in the internet, but couldn't find the solution. How to solve this? I am using Windows XP and IIS 5.1 version.

like image 854
thevan Avatar asked Jan 23 '26 02:01

thevan


1 Answers

How do you expect your Web Application to do a Process.Start when you deploy this site to a server, your just going to be opening pictures on the server, not on the client PC.

I think this will answer your question: http://www.codeproject.com/Articles/74654/File-Download-in-ASP-NET-and-Tracking-the-Status-o

Also the download file is missing a slash after E:\Documents

like image 195
Jeremy Thompson Avatar answered Jan 24 '26 14:01

Jeremy Thompson