开发者

OpenFileDialog Control - How Can I Grab the Selected Path and Show it in a Text Box?

开发者 https://www.devze.com 2023-01-06 03:49 出处:网络
Here is my snippet: private void btnBrowseCInv_Click(object sender, EventArgs e) { ofdBrowseVInv.Title = \"Locate Customer Invoice File\";

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.CheckFileExist开发者_运维技巧s = 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 http://img708.imageshack.us/img708/54/99763211.jpg


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);


string filename = System.IO.Path.GetFileName(ofdBrowseVInv.FileName); 
string path = System.IO.Path.GetDirectoryName(ofdBrowseVInv.FileName); 
0

精彩评论

暂无评论...
验证码 换一张
取 消