开发者

overwrite option file to user?

开发者 https://www.devze.com 2023-02-28 03:52 出处:网络
I need to create a binary file in a directory or path, if the file exists, the applicationshould ask to the user if want to overwrite it. I have this code to write the file, so, how can verify if the

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

精彩评论

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