Click here to Skip to main content
15,125,968 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Save the image in asp.net using C#

When i run the local machine the image saves.

But when i run in the server error shows as follows:

My code as follows:

C#
Bitmap bitmap = new Bitmap(990, 540);
            Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
            graphics.CopyFromScreen(5, 160, 0, 0, bitmap.Size);
            bitmap.Save(@"\\director\transfer\staff\NIRANJAN\" + ddlSession.Text.ToString().Trim() + "DailySchedule.bmp", ImageFormat.Bmp);


The error shows as follows:

Exception Details: System.ComponentModel.Win32Exception:
The handle is invalid

Line 35: graphics.CopyFromScreen(5, 160, 0, 0, bitmap.Size);

please help me.

what is the problem

Regards,
Narasiman P.
Posted
Updated 3-Sep-13 3:40am
v2
Comments
asbis 3-Sep-13 8:33am
   
try to use servwer.mappath
ZurdoDev 3-Sep-13 8:36am
   
It's likely a permissions issue.

Might be a long shot -

This function copies from a Device Context.
When the screen is locked, the image of the desktop might not exist anywhere,
Check if this exception is thrown when the screen is locked... (you do use a screen on this server do you?)
   
v2
Comments
Joezer BH 3-Sep-13 8:40am
   
5ed!

Good thinking, whether it is the issue or not :)
Jo Mua`mar 3-Sep-13 8:41am
   
Tnx!
Do you have permission? On your local machine, you probably have full permission for the folder structure "C:\Director\Transfer\Staff\Niranjan\" but on the production server it is likely to be more tightly locked down. Check that every folder in the path exists on the server, and that the appropriate permissions are given.

And the other thing - you aren't expecting this to take a snapshot of the client PC, are you? Because it will, on your development machine...but there is not a chance in heck of it working in production where the server and client are separate machines!
   

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