Results 1 to 2 of 2

Thread: How do you display the file name and path in Me.Text ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    How do you display the file name and path in Me.Text ?

    What I'm trying to do is put the file name and path up in the title of the form when I click on "New", "Append", "Inquiry", and "Lookup." All I get is "OpenFileDialog1" or a blank that removes the date and time and other text. I've included the code and a print screen of the form below.

    Code:
    Option Strict On
    Imports System.IO
    
    Public Class frmTitle
    
        Dim outPutFile As StreamWriter
        Dim inPutFile As StreamReader
        Dim OutOpen, InOpen As Boolean
    
        Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
    
            Dim fpath As String = ofdOpenFile.FileName
            Dim fbd As New FolderBrowserDialog
            Dim mainPath As String
            If fbd.ShowDialog = DialogResult.OK Then
                mainPath = fbd.SelectedPath
            End If
    
            sfdSaveFile.Filter = "Inventory files (*.emp)|*.txt|All files (*.*)|*.*"
    
            If sfdSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
    
                outPutFile = File.CreateText(sfdSaveFile.FileName)
    
            End If
    
            grpEmpData.Enabled = True
            btnSave.Enabled = True
            btnNext.Enabled = False
            btnFind.Enabled = False
    
            If NewToolStripMenuItem.Enabled = True Then
    
                NewToolStripMenuItem.Enabled = False
                AppendToolStripMenuItem.Enabled = False
                InquiryToolStripMenuItem.Enabled = False
                LookUpToolStripMenuItem.Enabled = False
                CloseToolStripMenuItem.Enabled = True
                'ofdOpenFile.ShowDialog = Windows.Forms.DialogResult.OK
                'Me.Text = mainPath
                Me.Text = ofdOpenFile.FileName
    
    
            End If

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: How do you display the file name and path in Me.Text ?

    you're not using an openfiledialog.
    you have a folderbrowserdialog + a savefiledialog that you're using correctly...

    Code:
    Dim outPutFile As StreamWriter
    Dim inPutFile As StreamReader
    Dim OutOpen, InOpen As Boolean
    
    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
    
        Dim fpath As String = ofdOpenFile.FileName
        Dim fbd As New FolderBrowserDialog
        Dim mainPath As String
        If fbd.ShowDialog = DialogResult.OK Then
            mainPath = fbd.SelectedPath
        End If
    
        sfdSaveFile.Filter = "Inventory files (*.emp)|*.txt|All files (*.*)|*.*"
    
        If sfdSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            outPutFile = File.CreateText(sfdSaveFile.FileName)
        End If
    
        grpEmpData.Enabled = True
        btnSave.Enabled = True
        btnNext.Enabled = False
        btnFind.Enabled = False
    
        If NewToolStripMenuItem.Enabled = True Then
    
            NewToolStripMenuItem.Enabled = False
            AppendToolStripMenuItem.Enabled = False
            InquiryToolStripMenuItem.Enabled = False
            LookUpToolStripMenuItem.Enabled = False
            CloseToolStripMenuItem.Enabled = True
            'ofdOpenFile.ShowDialog = Windows.Forms.DialogResult.OK
            'Me.Text = mainPath
            Me.Text = ofdOpenFile.FileName
    
        End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width