title: displaying htm contents in browser via Response.Writefile in ASP.Net
body: <p>I'm working on a site that I've inherited that's built with ASP.Net, which I'm only slightly familiar with.  One of the pages allows for a link to a document (word or pdf) that, when clicked on, prompts the user to save or open the file, but does not reveal the true path of the file.  This way it prevents users from pasting a url to a file - the link is to an aspx file that checks for a valid session, and then retrieves the file.</p>
  
  <p>Anyway, because there's a lot of legacy code, I need to do this with a bunch of static htm files as well, however these files need to be displayed rather than prompting the user to save them, which is what happens now.  I tried changing the content type to application/text, application/html, text/html, etc. and that didn't work, then tried adding a response header of  content-disposition inline.  When I do that, build, and try linking to the file, I get a couple of runtime exceptions:</p>
  
  <pre><code>[FormatException: Input string was not in a correct format.]
  Microsoft.VisualBasic.CompilerServices.Conversions.ParseDecimal(String Value, NumberFormatInfo NumberFormat) +206
  Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value) +110
  
  [InvalidCastException: Conversion from string "inline; filename=\" + myFile + " to type  'Long' is not valid.]
  Microsoft.VisualBasic.CompilerServices.Conversions.ToLong(String Value) +428
  cmswebasp.CMSModdoclinks.DownloadFile(String file) +1704
  cmswebasp.CMSModdoclinks.Page_Load(Object sender, EventArgs e) +625
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +50
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
  </code></pre>
  
  <p>Here's a snippet of code from the page:</p>
  
  <pre><code>Response.AddHeader("Content-Disposition", "inline; filename=" &amp; file)
  
  
  Dim fi As New FileInfo(myFile)
  Response.AddHeader("Content-Length", fi.Length)
  
  Dim contentType As String = ""
  Dim fileExt As String = file.Split(".")(1)
  
  Select Case fileExt
  
  Case "htm"
  contentType = "application/text"
  Case Else
  contentType = "application/octet-stream"
  End Select
  
  Response.ContentType = contentType
  Response.WriteFile(myFile)
  </code></pre>
  
  <p>Do I have to do something with an htmlwriter object or something?  Can't I just have it open a new browser window with the file displaying or does it have to prompt the user if used in this way??</p>