title: save button, save webpage as mht file (.net 4 vb)
body: <p>I have a website written in .net 4. I'd like to include a save button on one the pages that will save the webpage as a mht file. This way the user can save the page as a mht file type on his/her desktop without have to use the browser toolbar. </p>
  
  <p>I'm currently working with the following code but I need to modify it so it to capture the url of the current page the user is viewing verses hard coding the url into the button click event. Thanks.  </p>
  
  <pre><code>Partial Class Form1
      Inherits System.Web.UI.Page
  
  End Class
  
  Public Class Form1
  
      Private Sub Button1_Click(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) Handles Button1.Click
          SavePage("http://forums.microsoft.com/MSDN/default.aspx", "C:\msdn.mht")
      End Sub
  
      Private Sub SavePage(ByVal Url As String, ByVal FilePath As String)
          Dim iMessage As CDO.Message = New CDO.Message
          iMessage.CreateMHTMLBody(Url, _
          CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")
          Dim adodbstream As ADODB.Stream = New ADODB.Stream
          adodbstream.Type = ADODB.StreamTypeEnum.adTypeText
          adodbstream.Charset = "US-ASCII"
          adodbstream.Open()
          iMessage.DataSource.SaveToObject(adodbstream, "_Stream")
          adodbstream.SaveToFile(FilePath, _
                    ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
      End Sub
  
  End Class
  </code></pre>