Reputation: 441
i am actually working on an application where a blob file is retrieved from my database, converted to the original file and then saved on the desktop. I would like to know if it is possible to check if a file named "xxx" already exists on the desktop and then it shall prompt me for another name. Here is my code:
myData.Read();
FileSize = myData.GetUInt32(myData.GetOrdinal("filesize"));
rawData = new byte[FileSize];
myData.GetBytes(myData.GetOrdinal("file"), 0, rawData, 0, (int)FileSize);
// must change paths
String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
fs = new FileStream(@desktopPath + "\\" + myData.GetString("title") + myData.GetString("extension"), FileMode.OpenOrCreate, FileAccess.Write);
myFilePath = desktopPath + "\\" + myData.GetString("title") +myData.GetString("extension");
fs.Write(rawData, 0, (int)FileSize);
fs.Close();
Upvotes: 0
Views: 735
Reputation: 13033
I do not see where you use OpenFileDialog
in your code, but you should use SaveFileDialog
class for saving files and set it's property CheckFileExists=true
Upvotes: 0