I need to create a binary file in a directory or path, if the file exists, the application should ask to the user if want to overwrite it. I have this code to write the file, so, how can verify if the file exist and show to console the message?
using (FileStream fileStream = new FileStream(binaryFilePath, FileMode.Create)) // destiny file directory.
{
using (BinaryWriter binaryWriter = new Bin开发者_如何学CaryWriter(fileStream))
{
for (int i = 0; i < frameCodes.Count; i++)
{
binaryWriter.Write(frameCodes[i]);
}
}
}
thanks..
File.Exists(binaryFilePath)
should help you.
You could try something like this:
if(File.Exists(binaryFilePath) && PromptUser())
{
...
}
Where PromptUser()
will ask the user if they want to override the file
精彩评论