C# Image Problem

Mahen Singh
Mahen Singh used Ask the Experts™
on
when I save a record with Image, it will save perfectly but when I updated the record again for Image it will say System.IO.IOException: "The file exists" on windows 7 64 bit . The installation directory is with read only attribute , I tried the best to remove this attribute but could not make it.
Can u help me out
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
Modify your Save method to first delete an existing file, then save the new/modified image file.

Of course, if you are granted read-only rights only, you are hosed. If so, use another install and/or work directory where the user has full rights. The recommended location is a subfolder under %localapppath%.

/gustav

Author

Commented:
I am doing in same way.. but in some cases this error occurs ....I have also attached the screenshot
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Well, the program files folder is definitely not the place to store user files, so try playing by the rules and use %localapppath%.

/gustav

Author

Commented:
Can u explain it with detail.. did not get your point exactly..?
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Try to save your files in a sub folder of the %localappdata%.

The Program Files folder is not intended for this purpose.

/gustav

Author

Commented:
There must be solution.. I think , if we install on client machine it would be installed on program file directory..
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
No. Normal user rights doesn't grant right to save anything in the Program Files folder. You need Admin rights, and a normal user should never be required to run your application with admin rights.

It's up to you to control the installation.

Author

Commented:
k.. then how to give the rights to normal user ....like admin rights. In that case it wont be a prob.
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
You can set your application to require admin rights. That will pop the usual warning message and ask the user for credentials for an admin account.
But to save some pictures, this is bad practice and should be avoided. Again, use %localappdata% for storing user documents and files.

/gustav
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Question was answered.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial