Hello all,
I want to save a file, so I show user save file dialog.
But when user selects an existing file and confirm its overwrite, I cannot simply set its attribute to normal and delete it, then overwrite it!
I have to check if its not either read only or hidden or system, then delete and overwrite it, am I right?
So I use this code to do the check, but it wont work, it always returns that the file is locked, even if the file is archive only!
What should I do?
I want to save a file, so I show user save file dialog.
But when user selects an existing file and confirm its overwrite, I cannot simply set its attribute to normal and delete it, then overwrite it!
I have to check if its not either read only or hidden or system, then delete and overwrite it, am I right?
So I use this code to do the check, but it wont work, it always returns that the file is locked, even if the file is archive only!
What should I do?
Code:
If My.Computer.FileSystem.FileExists(SaveFileDialog.FileName) Then
If System.IO.File.GetAttributes(SaveFileDialog.FileName) <> FileAttributes.Archive And System.IO.File.GetAttributes(SaveFileDialog.FileName) <> FileAttributes.Normal Then
MessageBox.Show("The output file is locked." + vbNewLine + "Please use a different file name.", My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
End If