It's hard to tell what the problem is, but the OS like to set lots of rules before you can access files.
What if you delete the file before copying?:
Ow, and you could try it with using a full path instead of a relative path:Code:If System.IO.File.Exists(sfd.FileName) Then SetAttr(sfd.FileName, FileAttribute.Normal) IO.File.Delete(sfd.FileName) End If IO.File.Copy("bob.txt", sfd.FileName, True)
But, since the error is about the "bob.txt" file (saw it too late), I might have a clue of what is going on. In case you wrote the file "bob.txt" in your program, do not forget to close your writer:Code:Dim sourcefile As String = Application.StartupPath & "\bob.txt" If IO.File.Exists(sourcefile) Then Dim sfd As New SaveFileDialog If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then Dim destfile As String = sfd.FileName If System.IO.File.Exists(destfile) Then SetAttr(destfile, FileAttribute.Normal) System.IO.File.Delete(destfile) End If IO.File.Copy(sourcefile, destfile) End If End If
If you used the System.IO.File.WriteAllText it could be the system forgot to close the writer.Code:Dim writer As New System.IO.StreamWriter("bob.txt", True) writer.WriteLine("line") writer.Close() '<- very important
Just in case, are you sure the file is not used by your program or was used in the past during the runtime of your program?





Reply With Quote