0

I have a HttpWebRequest that is currently downloading the file but I want to stop it downloading and save the file in a folder instead.

webRequest.Method = "GET";
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.ContentType = "text/xml;charset=UTF-8";
using (var webResponse = webRequest.GetResponse())
using (var webStream = webResponse.GetResponseStream())
{
    if (webStream != null)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "attachment; filename=\"test.pdf\"");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        webStream.CopyTo(Response.OutputStream);
        Response.Flush();
        Response.End();
    }
}

I have tried changing the ContactType to Response.ContentType = "application/x-download"; and adding Response.TransmitFile but the file still downloads.

Guilhem Prev
  • 979
  • 5
  • 17
user123456789
  • 1,914
  • 7
  • 44
  • 100
  • You want to control the client action from the server? That is a browser setting. Did you mean you want to save the file to a folder on the server? – mjw Jul 30 '19 at 14:53
  • @mjw yes the file is automatically going to the download folder but I want to save it another folder on the server – user123456789 Jul 30 '19 at 14:54
  • Possible duplicate of [How do I save a stream to a file in C#?](https://stackoverflow.com/questions/411592/how-do-i-save-a-stream-to-a-file-in-c) – mjw Jul 30 '19 at 15:00
  • @mjw I am not using a StreamReader object – user123456789 Jul 30 '19 at 15:08

0 Answers0