Reputation: 31
I’m trying to save file to D:\folder1\folder2\file.txt
using the following logic:
public void ChangeBackground(ChangeBackgroundDto dto)
{
var dir = Directory.GetCurrentDirectory();
File.WriteAllBytes("../../Images/Custom/BackgroundHome.png", dto.BGFileFormat);
}
However, when I do this, I recent an exception because I have root directory at C:\programfiles(x86)\llsExpress
.
The exception message is: Could not find a part of the path 'C:\\Images\\Custom\\BackgroundHome.png'.
What path which will work for this even when I deploy the application?
Upvotes: 1
Views: 890
Reputation: 858
First I'd suggest you to try to store your file in a relative path in the root folder if possible. This helps with security plus you'll know that all the files for your site are in the root folder.
If you really want to store files on a different drive, you cannot use relative paths to do this. So no ..
in your paths. You'll have to use the absolute path. Store that somewhere in config or environment variables to avoid configuring file paths hard coded.
Finally please use code blocks to show code rather then screenshots on StackOverflow.
You can do this by putting the code as text between these chars ``. like this
Upvotes: 1