简体   繁体   中英

Is it possible to take a screenshot of a web page with ASP.net with C# Code

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");

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 (eg 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.

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 : How do you take a Screenshot of a website via .Net code?

ere is another question about taking screenshot

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM