views:

516

answers:

2

I'm using some code from SmallSharpTools Web Preview to get screen shots of websites but i get a blank screen shot if the url returns a 301/302 redirect.

        WebBrowser wb = new WebBrowser(); 
        wb.ScrollBarsEnabled = false;
        wb.Size = new Size(1024, 768);
        wb.ScriptErrorsSuppressed = true;
        wb.AllowNavigation = true; 
        wb.NewWindow += new System.ComponentModel.CancelEventHandler(wb_NewWindow);
        wb.Navigate(url);
        // wait for it to load
        while (wb.ReadyState != WebBrowserReadyState.Complete)
        {
            Application.DoEvents();
        } 
        bitmap = new Bitmap(width, height);
        Rectangle rect = new Rectangle(0, 0, width, height);
        wb.DrawToBitmap(bitmap, rect);

I have tried accessing the ActiveXInstance that the Windows.Forms.WebBrowser wraps but i can only get the codes if there was an error (like 404/500) but i need to see if it was a 301/302 so that i can tell the page to redirect ( i guess that i would also need the redirect url)

If all else fails i could do a HTTPWebRequest and sort things out before hand, but then i would be making 2 requests for 1 page.

Thanks!

A: 

the webbrowser control doesn't support drawtobitmap according to msdn. you'll have to find another way

Timmo
A: 

It doesn't officially support it but it can work (it should not be relied upon).

Tom