Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have the same problem, here's my solution:</p> <p>You need to basically make an HTTP request to your own URL and save the output as a binary file. Simple, no overload, helper classes, and bloated code.</p> <p>You'll need this method:</p> <pre><code> // Returns the results of fetching the requested HTML page. public static void SaveHttpResponseAsFile(string RequestUrl, string FilePath) { try { HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(RequestUrl); httpRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; httpRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); HttpWebResponse response = null; try { response = (HttpWebResponse)httpRequest.GetResponse(); } catch (System.Net.WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)ex.Response; } using (Stream responseStream = response.GetResponseStream()) { Stream FinalStream = responseStream; if (response.ContentEncoding.ToLower().Contains("gzip")) FinalStream = new GZipStream(FinalStream, CompressionMode.Decompress); else if (response.ContentEncoding.ToLower().Contains("deflate")) FinalStream = new DeflateStream(FinalStream, CompressionMode.Decompress); using (var fileStream = System.IO.File.Create(FilePath)) { FinalStream.CopyTo(fileStream); } response.Close(); FinalStream.Close(); } } catch { } } </code></pre> <p>Then inside your controller, you call it like this:</p> <pre><code>SaveHttpResponseAsFile("http://localhost:52515/Management/ViewPDFInvoice/" + ID.ToString(), "C:\\temp\\test.pdf"); </code></pre> <p>And voilà! The file is there on your file system and you can double click and open the PDF, or email it to your users, or whatever you need.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload