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);
精彩评论