Could not find file - "Content-Disposition" in C#

1.1k views Asked by At

I have implemented Web file manager in my application. It shows the files from the FTP server. When i try to download the file by clicking on the file i'm getting the following error. Getting the error during WriteFile line getting executed.

Error:

Could not find file 'C:\Users\ ####\Desktop\SeekDotNetFileManager\AdminMaster.master.cs'.

//Code:

  Response.AddHeader("Content-Disposition", "attachment; filename=" + lnkName.Text.Trim());
  Response.WriteFile(lnkName.Text);
  Response.End();

In the lnkName.Text.Trim the name of the file will be set. Eg: AdminMaster.master.cs

Where i'm wrong?

1

There are 1 answers

0
A Coder On

Got a Solution:

//Code

            string filename = 'Get the full path of file'; //something like /httpdocs/Images/button.gif
            string strURL = "http://www.servername.com/";

            WebClient req = new WebClient();
            HttpResponse response = HttpContext.Current.Response;
            response.Clear();
            response.ClearContent();
            response.ClearHeaders();
            response.Buffer = true;
            response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
            byte[] data = req.DownloadData(strURL);
            response.BinaryWrite(data);
            response.End();