How to show full file path in TextBox?
I have a FileDialog...
string fileData = openFileDialog1.FileName;
...and a TextBox1. How to see the full path of the opened file in the TextBox1?
Solution:
textBox1.Text = string.Format("{0}", openFileDialog1.FileName)开发者_开发知识库;
using TextBox1.Text = openFileDialog1.FileName;
this is the best code it works 100% for me :
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PDF Files(*.pdf)|*.pdf|WORD Files(*.doc;*.docx)|*.doc;*.docx|EXCEL Files(*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt)|*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt|Image Files(*.jpg;*.gif;*.bmp;*.png;*.jpeg)|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
string path = ofd.FileName.ToString();
textBox1.Text = path;
}
see below code.
TextBox1.Text = string.Format("{0}/{1}",
Path.GetDirectoryName(fileData),openFileDialog1.FileName);
this should work:
TextBox1.Text = openFileDialog1.FileName;
if does not work, please refine your question telling exactly what you need to retrieve and giving examples.
you might want to check this one as well:
Extracting Path from OpenFileDialog path/filename
You may also use TextBox1.Text = fileUpload.PostedFile.FileName;
depending upon when you want to access the information.
After declaring variable, try this:
String filePath = openFileDialog1.FileName;
textbox1.Text = filePath;
精彩评论