"Cor" <no*@non.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
If someone chooses a file that already exist the savefiledialog ask if it
has to be overwritten. And if he sais "save" (depends on your
langagesettings), that is with this routine done (and when it not exist it
is just written).
Cor
Not sure if i explained my self properly before, I have a menu item ('Save')
that when you press it it will save the file. The code i posted (for
'Save') is suposed to check if you have saved the file before(by doing a
'Save As'), if you have, then it will save the file under that name('Save'),
but if you have not, it will ask you to name the file -ie, dialog box opens
(Imagine going to 'File' then 'Save' in note pad - it will ask you to give
it a name if it has not been saved before, but if you have already done a
'Save As', it will just save it).
If i do a 'save as' first, edit the text in rtb1, then click 'save' it will
work, but if i close the program, reopen it, edit the text in rtb1 and then
'save' it does not save it, i have messed around, its either the sub
'mnuSave_click' or the sub 'mnuOpen_click' that is giving me the problem,
but i cant work it out
Here the code:
''''I have the variable 'fname' that is used to check if the file already
has been saved (it will have a file name if it has)
''''Code for 'Save As':
Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSaveAs.Click
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End Sub
''''Code for 'Save'
Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSave.Click
'fname is a var, set it to file name
fname = SFD.FileName()
If fname > "0" Then
'save the file will current name
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
Else
'need to do a save as
SFD.Title = "Please chose a folder and a name for your file"
SFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
SFD.FilterIndex = 1
result = SFD.ShowDialog
If result = DialogResult.OK Then
rtb1.SaveFile(SFD.FileName, RichTextBoxStreamType.RichText)
fname = SFD.FileName
End If
End If
End sub
''''Code for open
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuOpen.Click
OFD.Title = "Please chose a folder and the name of your file"
OFD.Filter = "Rich Text Files (*.rtf)|*.rtf"
OFD.FilterIndex = 1
result = OFD.ShowDialog
If result = DialogResult.OK Then
rtb1.LoadFile(OFD.FileName)
fname = OFD.FileName
End If
Me.Text = OFD.FileName
End Sub