title: How to create and download an XML without storing it on the server
body: <p>I have an <strong>ASP.NET Web Forms</strong> application. I would like to create a download link to make available to the user the possibility to download an <strong>XML file</strong>. However the file does not have to be stored on the server.</p>
  
  <p>In my <strong>aspx</strong> file I have the download link (placed inside a GridView):</p>
  
  <pre><code> &lt;asp:HyperLinField Text="Download" DataNavigateUrlFormatString="download.aspx?ProductId={0}" DataNavigateUrlFields="ProductId"&gt;
  </code></pre>
  
  <p>In the <strong>download.aspx.vb</strong> page:</p>
  
  <pre><code>Dim productId As String = Request.QueryString("productId")
  Dim xmlDoc As String = _ProductServices.GetXmlDocPerId(productId)
  Dim xdoc As XmlDocument = New XmlDocument()
  xdoc.LoadXml(xmlLicense)
  </code></pre>
  
  <p>Now I would like to create a file, place the XML content inside and deliver it to the user without saving it to the server. Shall I use a <code>MemoryStream</code> combined with a <code>StreamReader</code>?</p>