开发者

overwrite option file to user?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜