0

I am thinking about using a WebBrowser object to create a screen shot of a page a user has visited (by capturing the URL). Part of the class will look something like tHE below. This is an internal application and the reason is to allow the user to see how the dynamic page looked several months ago when they last visited.

Public Function ConvertPage(ByVal PageUrl As String) As Bitmap
        Me.PageUrl = PageUrl
        Dim thrCurrent As New Thread(New ThreadStart(AddressOf CreateImage))
        thrCurrent.SetApartmentState(ApartmentState.STA)
        thrCurrent.Start()
        thrCurrent.Join()
        CreateImage()
        Return ConvertedImage
    End Function
Private Sub CreateImage()

    Dim BrowsePage As New WebBrowser()
    BrowsePage.ScrollBarsEnabled = False
    BrowsePage.Navigate(PageUrl)
    AddHandler BrowsePage.DocumentCompleted, AddressOf _
WebBrowser_DocumentCompleted

    While BrowsePage.ReadyState <> WebBrowserReadyState.Complete
        Application.DoEvents()
    End While
    BrowsePage.Dispose()
End Sub

Earlier today I was reading an entry (I think it was on here) and the answerer advised the questioner to avoid this approach. I do not have a link to this post. Is this a poor apprach bin your view i.e. using a WebBrowser object in an ASP.NET page?

TheBoyan
  • 6,802
  • 3
  • 45
  • 61
w0051977
  • 15,099
  • 32
  • 152
  • 329

1 Answers1

1

I think this is the link you are after.
problem using winforms WebBrowser in asp.net

This code project page seems to have a solution and talks about the advantages of it http://www.codeproject.com/Articles/50544/Using-the-WebBrowser-Control-in-ASP-NET

His solutions seems to require three threads to use the control;

perhaps a better options would be to take a via Javascript and then post the information back via an ajax call, have a look at this Javascript library that does it http://html2canvas.hertzen.com/

if you are going with the webbrowser approach att the bottom of this question is c# code for capturing the image

Take a screenshot of a webpage with JavaScript?

Community
  • 1
  • 1
Ricky Gummadi
  • 4,559
  • 2
  • 41
  • 67