How do you send a notification to the user that the program cannot Autosave a file, while it is in use on another program? It cannot be saved even if there is a timer on the program on the RichTextBox_TextChanged event(). Here is the function:
Code:Private Sub AutosaveFile() Dim path As String = (My.Computer.FileSystem.SpecialDirectories.Desktop & "\Common-Mistakes-Backup.rtf") ' This text is added only once to the file. If File.Exists(path) = False Then Using fs As FileStream = File.Create(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Common-Mistakes-Backup.rtf") fs.Close() ' Save the contents of the RichTextBox into the file. RichTextBox1.SaveFile(path, RichTextBoxStreamType.RichText) Timer1.Start() End Using End If Try ' Delete the file if it exists. If File.Exists(path) = True Then ' Save the contents of the RichTextBox into the file. RichTextBox1.SaveFile(path, RichTextBoxStreamType.RichText) Timer1.Start() End If Catch ex As Exception Console.WriteLine(ex.ToString()) End Try End Sub




Reply With Quote
