Try ending the Response after Response.Write()

Response.WriteFile(file.FullName);
Response.End();

Let us know if it works for you

On Dec 7, 5:11 pm, uttam24 <[email protected]> wrote:
> I have hosted one of my  asp.net project  server. In my works there is
> a need of downloading the files(.doc/.gif/.jpeg ) which are uploded by
> user. Now my downloading code which are working fine in local machine
> is not working in server.
>
> My code are as below..(here file path is changed to my website)
>
> string filepath = Path.GetFullPath(@"http://www.mysite.com/
> Pics/"squirrel.gif);
>             FileInfo file = new FileInfo(filepath);
>             if (file.Exists)
>             {
>
>                 Response.Clear();
>                 Response.AddHeader("Content-Disposition",
> "attachment;filename=" + file.Name);
>                 Response.AddHeader("Content-Length",
> file.Length.ToString());
>                 Response.ContentType = "application/msword";
>                 Response.WriteFile(file.FullName);
>             }
>             else
>             {
>                 lblEditMessage.Text = "File not found";
>             }
>
> It gives me the error as   URI formats are not supported
>
> I also used the other following code also
>
> protected void Button1_Click(object sender, EventArgs e)
>
> {
>
>      GetImage("http://www.mysite.com/Pics/squirrel.gif";);
>
> }
>
> private static void GetImage(string url)
>     {
>         HttpWebRequest request =
> (HttpWebRequest)WebRequest.Create(url);
>         request.Accept = "image/gif";
>         HttpWebResponse response =
> (HttpWebResponse)request.GetResponse();
>         Stream s = response.GetResponseStream();
>         Bitmap bmp = new Bitmap(s);
>     }
>
> It gives me the error as..
>
> The remote server returned an error: (406) Not Acceptable.
>
> Line 146:        request.Method = "GET";
> Line 147:        request.Accept = "image/gif";
> Line 148:        HttpWebResponse response =
> (HttpWebResponse)request.GetResponse();
> Line 149:        Stream s = response.GetResponseStream();
> Line 150:        Bitmap bmp = new Bitmap(s);
>
> Pls give suggestion to proceed in my works

Reply via email to