tags:

views:

233

answers:

2

I'm doing a simple image resize and on the final I want to save it like:

path = "C:\\new_image.jpg";
img.Save(path, jpegCodec, encoderParams);

The problem is it saves to "....... \Users\Ervin\AppData\Local\VirtualStore\" . What did I do wrong or what did I miss out?

UPDATE: I changed the path to an other folder, and it works. it seems I can't save to C:\ only.

+2  A: 

The resion for this is the user you are running as does not have write permissions to write directly to the C: drive this was new to either Win7 or Vista I am not shure which.

You can solve this by:

  1. Saving in a directory other than the root of C:
  2. Changing the permissions on the C: drive so people other than the administrators group have write access.
  3. Run your program with elevated privileges.

....... \Users\Ervin\AppData\Local\VirtualStore\ was added to help fix legacy applications when you updated. You may also notice a lot of entries in the "Program Files" in the virtual store. these are programs trying to write to their own directory in program files instead of %LOCALAPPDATA% like they should.

Scott Chamberlain
Still surprised it wouldn't throw an exception when failing to write the explicit path specified.
Kirk Woll
I edited my answer. they added the virtual store instead of throwing a exception to keep the millions of programs out there that write where they should not from throwing a exception.
Scott Chamberlain
Typically, you should be saving application data to %AllusersProfile% folder which in Vista and above points to c:\programdata. This will avoid the virtualization thing that will happen when you write to c: c:\windows, or other folder where only administrators have access to write to.
Santhosh
Thanks I did not know which of the system variables you should use. I just kind of stabbed in the dark and looked at the one that seemed most likely.
Scott Chamberlain
+1  A: 

This was introduced in Vista, called Virtualization:

File virtualization addresses the situation where an application relies on the ability to store a file, such as a configuration file, in a system location typically writeable only by administrators. Running programs as a standard user in this situation might result in program failures due to insufficient levels of access.

When an application writes to a system location only writeable by administrators, Windows then writes all subsequent file operations to a user-specific path under the Virtual Store directory, which is located at %LOCALAPPDATA%\VirtualStore. Later, when the application reads back this file, the computer will provide the one in the Virtual Store. Because the Windows security infrastructure processes the virtualization without the application’s assistance, the application believes it was able to successfully read and write directly to Program Files. The transparency of file virtualization enables applications to perceive that they are writing and reading from the protected resource, when in fact they are accessing the virtualized version.

Jon Skeet