I created an open file dialog to open an image from my computer and than display the picture in the picture box and it's path in a textbox.. The problem is that it is not getting the whole path in the text box example if teh path is:

C:\Users\Anna Marie\Desktop\Software Project Assignment\Images\Pictures\ChickenSalad.jpg

it is giving me the path without the image name:
C:\Users\Anna Marie\Desktop\Software Project Assignment\Images\Pictures\

This is my code:

private void ItemPictureDialog()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "Libraries\\Documents";
            openFileDialog1.Filter = "(*.jpg; *.jpeg; *.gif; *.bmp, *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                picItem.ImageLocation = openFileDialog1.FileName;
                txtImagePath.Text = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
            }
        }


private void btnBrowsePicture_Click(object sender, EventArgs e)
        {
            ItemPictureDialog();   
        }

I can't figure it out could you help me pls?

change line # 13 to

txtImagePath.Text =System.IO.Path.GetFullPath(opf.FileName)

worked thx :)

On line 13 you called a method to give you the directoryname(GetDirectoryName), so that is what you get.

Please mark this thread solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.