• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

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
0
Durkis007
Asked:
Durkis007
  • 4
  • 2
1 Solution
 
Fernando SotoCommented:
Hi Durkis007;

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
0
 
Durkis007Author Commented:
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.FileName, RichTextBoxStreamType.RichText)
           
            ' 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
0
 
Fernando SotoCommented:
Here is what you need to do.

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.FileName, RichTextBoxStreamType.RichText)
           
        ' Store the file name in the form's title bar.
        Dim index As Integer
        Dim tBar As String
        ' Did not want to distroy sfdSave.Filter just in case it is used again
        tBar = sfdSave.FileName
        index = tBar.LastIndexOf("\")
        Me.Text = tBar.Remove(0, index - 1)

        End If
    End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Fernando SotoCommented:
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
0
 
Durkis007Author Commented:
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
0
 
Fernando SotoCommented:
You are correct Derek should be plus 1. I found the index of "\" to get the file name you must increment by one.

Great
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now