I'm running a wcf service hosted on iis express 7.5. Inside the service, i have a service operation that needs to write a file on the filesystem, but when it tries to do so, i'm getting an exception.
i'm writing the file to the exact same folder where the project is hosted, by using: string filePath = HttpContext.Current.Server.MapPath(".");
but i keep getting this exception:
DirectoryNotFoundException - "Could not find a part of the path C:\websites....
It seems like my iis express doesn't have permission to write files. if so, how do i give it permission?
thanks!
IIS Express runs under current logged on user identity. If the folder you are trying to write has some special access, then provide acccess to current user.
File.Open(filePath, FileMode.Create) would create only files, if the directory does not exit, it throws 'DirectoryNotFound' exception and it is expected. So, before creating a file, make sure that directory exists. probably you can use Directory.CreateDirectory("directory path") API