user922907
user922907

Reputation: 569

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

Upvotes: 0

Views: 29280

Answers (6)

Gsspl Utkasrh
Gsspl Utkasrh

Reputation: 1

After declaring variable, try this:

String filePath = openFileDialog1.FileName;
textbox1.Text = filePath;

Upvotes: 0

nassimlouchani
nassimlouchani

Reputation: 423

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

Upvotes: 2

Henry
Henry

Reputation: 1008

see below code.

TextBox1.Text = string.Format("{0}/{1}",
    Path.GetDirectoryName(fileData),openFileDialog1.FileName);

Upvotes: 1

McArthey
McArthey

Reputation: 1646

You may also use TextBox1.Text = fileUpload.PostedFile.FileName; depending upon when you want to access the information.

Upvotes: 0

Davide Piras
Davide Piras

Reputation: 44605

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

Upvotes: 1

Waqas
Waqas

Reputation: 6812

using TextBox1.Text = openFileDialog1.FileName;

Upvotes: 6

Related Questions