Reputation: 893
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.
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.
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
Upvotes: 0
Views: 1807
Reputation: 21
You need to Add COM References to the 'Microsoft CDO For Windows 2000 Library' and 'Microsoft ActiveX Data Objects 2.5 Library'. Then import them:
Imports ADODB
Imports CDO
Upvotes: 2
Reputation: 14387
Try this:
SavePage(HttpContext.Current.Request.Url.AbsoluteUri, "C:\whatever.mht")
Upvotes: 0