Durkis007
asked on
A MDI file, When Saving a document I need the file name in the title bar.
Hello,
I have a MDI parent form and it opens MDIChild forms within it.
When i go to save my document it puts the whole file path into the title bar area.
i.e. C:\Scratch\Test.rtf
The question is:
I need it to just say: Test.rtf
How do I trim the file path off and just keep the file name I assigned it ?
I hope you under stand the question.
Thank You
Derek
I have a MDI parent form and it opens MDIChild forms within it.
When i go to save my document it puts the whole file path into the title bar area.
i.e. C:\Scratch\Test.rtf
The question is:
I need it to just say: Test.rtf
How do I trim the file path off and just keep the file name I assigned it ?
I hope you under stand the question.
Thank You
Derek
ASKER
Hello,
I am not sure how to implement this code you gave me...
Here is what i have before your code:
' Save the file as an RTF file.
Private Sub SaveFile()
Dim dlgResult As DialogResult
sfdSave.Filter = "RTF Files (rtf)|*.rtf|All Files (*.*)|*.*"
dlgResult = sfdSave.ShowDialog()
If dlgResult = DialogResult.OK Then
rtfEdit.SaveFile(sfdSave.F ileName, RichTextBoxStreamType.Rich Text)
' Store the file name in the form's title bar.
Me.Text = sfdSave.FileName
End If
End Sub
Where would i insert your code in this?
Thank You
Derek
I am not sure how to implement this code you gave me...
Here is what i have before your code:
' Save the file as an RTF file.
Private Sub SaveFile()
Dim dlgResult As DialogResult
sfdSave.Filter = "RTF Files (rtf)|*.rtf|All Files (*.*)|*.*"
dlgResult = sfdSave.ShowDialog()
If dlgResult = DialogResult.OK Then
rtfEdit.SaveFile(sfdSave.F
' Store the file name in the form's title bar.
Me.Text = sfdSave.FileName
End If
End Sub
Where would i insert your code in this?
Thank You
Derek
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If it is possable for sfdSave.FileName not to have the path information, just a file name then you will want to test for that.
index = tBar.LastIndexOf("\")
If index < 0 Then
' No file path info
Me.Text = sfdSave.FileName
Else
' Remove file path info
Me.Text = tBar.Remove(0, index - 1)
End If
index = tBar.LastIndexOf("\")
If index < 0 Then
' No file path info
Me.Text = sfdSave.FileName
Else
' Remove file path info
Me.Text = tBar.Remove(0, index - 1)
End If
ASKER
Awsome... Great thanks again!!!
Worked Well..
however i had to modify it slightly...
this line:
Me.Text = tBar.Remove(0, index - 1)
i had to change to:
Me.Text = tBar.Remove(0, index + 1) <----- I ADDED THE PLUS INSTEAD OF THE - 1
this is because it was giving me the ---> h\Test.rtf (the last slash and 1 character befor the slash... so i changed it to the plus sign and it corrected it.
Thanks Again
Derek
Worked Well..
however i had to modify it slightly...
this line:
Me.Text = tBar.Remove(0, index - 1)
i had to change to:
Me.Text = tBar.Remove(0, index + 1) <----- I ADDED THE PLUS INSTEAD OF THE - 1
this is because it was giving me the ---> h\Test.rtf (the last slash and 1 character befor the slash... so i changed it to the plus sign and it corrected it.
Thanks Again
Derek
You are correct Derek should be plus 1. I found the index of "\" to get the file name you must increment by one.
Great
Great
To trim the file path off do the following:
Dim filePath As String
Dim index As Integer
index = filePath.LastIndexOf("\")
filePath = filePath.Remove(0, index - 1)
The write it out to the title bar