views:

377

answers:

4

Is it possible to take a screenshot of a web page with ASP.net with C# Code and then submit that back to the server? In this code access only local host only, but same source code not access to the IIS, CopyFromScreen error ware occurred. What is the reason is it possible?

Sample Source Code:

Bitmap Bitmap;
Graphics Graps;
Bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height - 110, PixelFormat.Format32bppArgb);
Graps = Graphics.FromImage(Bitmap);
Graps.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, 110, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Bitmap.Save(Server.MapPath("~") + "/YourShot.gif");
A: 

I am little confused. You are taking the screenshot of the server and saving it there? Whats the point in it?

What exactly are tring to do here? If you want to take the screen shot of a web page then you might want to look at this question.

We have another question here : http://stackoverflow.com/questions/653834/how-do-you-take-a-screenshot-of-a-website-via-net-code

ere is another question about taking screenshot

Shoban
A: 

I was interested in this topic. So I followed the link I posted for you and tried my hand at getting it to work. As it turned out this worked very well. If you need help getting it working let me know. I have a working ASP.NET MVC sample. It is great!

Andrew Siemer
A: 

Using a bitmap (even a JPG) strikes me as a very expensive way to store the web page and also one that you wouldn't be able to easily parse or compare with different versions (e.g. on different dates). If you'd like to explore the alternative - pulling the web site HTML down to the server, just do this:

WebRequest wrContent = WebRequest.Create("http://www.destsite.com/yourpage.aspx");
Stream objStream = wrContent.GetResponse().GetResponseStream();
StreamReader objStreamReader = new StreamReader(objStream);
string pageContent = objStreamReader.ReadToEnd();

Hope this helps...something to think about, anyway.

Mark Brittingham