Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am capturing the webpage as screen shot and save the screen shot in folder.

Capture image code as follows

C#
protected void btnCapture_Click(object sender, EventArgs e)
 {

 Bitmap bitmap = new Bitmap
 (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

bitmap.Save(Server.MapPath(@"File\ScreenShot.bmp"), ImageFormat.Bmp);

}



But when i run the above code shows error as follows

A generic error occurred in GDI+.


please kindly help me what is the problem in my above code.
Posted
Updated 6-Oct-15 18:43pm
v2
Comments
[no name] 7-Oct-15 0:58am    
Please check folder permission that you have write permission to that folder. Secondly please check you are correct file path when using Server.Mappath().
StM0n 7-Oct-15 1:06am    
Could you specify the line the error occurs? I'm not quite sure, if it is a permission or server problem...
sreeyush sudhakaran 7-Oct-15 1:24am    
This purely error with accessibility of your sever
vangapally Naveen Kumar 7-Oct-15 1:29am    
Check the permission to the folder where you are saving the file.That folder should be have Read/write permissions.

1 solution

There are two things here, and the error you get is not the big one!
The big problem is
That that code isn't going to capture the webpage, except on your development machine - C# code runs on the server, not the client, and has no access to the client display.
It "works" on the development machine only because the client and server are the same computer.

The problem you have noticed is probably the Server.MapPath trying to work with a folder that isn't there (the path is relative to the current page , and you probably want:
C#
bitmap.Save(Server.MapPath(@"~\File\ScreenShot.bmp"), ImageFormat.Bmp);

Or the folder does not have the appropriate access permissions set so the folder does not have write permission for the user running the IIS code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900