Reputation: 1061
I have a function which lets the user edit an image when they do this I save this new image to a file to which they I save to the database etc ...
The issue comes as when I try and look for the file I just saved it says it does not exist but it does?
Here I am saving the new file to the TEMP folder:
string newFullTempFolderURL = Path.Combine(Global.TempFolder, newFullFileName + ".png");
_image.Save(newFullTempFolderURL, System.Drawing.Imaging.ImageFormat.Png);
At this point when I check the folder the file is in the folder with the new image.
Then when I go on to uploading the file to the server (Using BITS) I do a check to make sure the file exists:
if (File.Exists(Path.Combine(Global.TempFolder + "\\" + newFullFileName)))
{
}
This then returns false (Not exists) when i can see the file with my own eyes!
Anyone had this same issue?
EDIT1:
newFullFileName already contains .png:
string newFullFileName = string.Format(oldFileName.Substring(0, oldFileName.IndexOf("_") + 1) + DateTime.Now.ToString(), "yyyyMMddhhmmss").Replace(@"/", "").Replace(" ", "").Replace(":", "") + ".png";
Upvotes: 1
Views: 1025
Reputation: 7766
As per your edit you are added .png to newFullFileName.. then newFullTempFolderURL will add another .png to your file name.
So ti will become FILENAME.png.png it will return wrong.
remove .png from newfullFilename and
try below
if (File.Exists( Path.Combine(Global.TempFolder, newFullFileName))
{
}
Upvotes: 6
Reputation: 1579
your File.Exists does not contain the file extension as you manually added it when creating "newFullTempFolderURL". You need to append ".png" to the File.Exists check or better yet use File.Exists(newFullTempFolderURL); as it's already been pre-made.
EDIT1: You are adding ".png" a second time. This is wrong, as the file created is ".png.png", and then you are checking to see if ".png" exists.
Upvotes: 4