views:

29

answers:

2

Here is my snippet:

private void btnBrowseCInv_Click(object sender, EventArgs e)
{
  ofdBrowseVInv.Title = "Locate Customer Invoice File";
  ofdBrowseVInv.Filter = "Portable Document Format (*.pdf)|*.pdf|All Files (*.*)|*.*";
  ofdBrowseVInv.FileName = "";
  ofdBrowseVInv.FilterIndex = 0;

  ofdBrowseVInv.InitialDirectory = "";

  ofdBrowseVInv.CheckFileExists = true;
  ofdBrowseVInv.CheckPathExists = true;

  if (ofdBrowseVInv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
     //txtInvoicePathCInv.Text = ofdBrowseVInv... What property should i use?
  }
}

As you see below, once a user pick a file and click open. I want the selected path to show on the pointed text box which is named "txtInvoicePathCInv". Any idea?

I'm using Windows Application...

alt text

+1  A: 
string filename = System.IO.Path.GetFileName(ofdBrowseVInv.FileName); 
string path = System.IO.Path.GetDirectoryName(ofdBrowseVInv.FileName); 
Ahmet Kakıcı
+1  A: 

Use the FileName property:

txtInvoicePathCInv.Text = ofdBrowseVInv.FileName;

This will give you the whole path, but you can always just use the directory part of it, using Path.GetDirectoryName:

txtInvoicePathCInv.Text = Path.GetDirectoryName(ofdBrowseVInv.FileName);
Oded