Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Visual Studio 2008 on Windows XP, the problem is that I am trying to open a file dialog box to select a file, and on WinXP this works fine but on Windows7 the file dialog does not show. This is my code

C#
OpenFileDialog FD = new OpenFileDialog();


C#
FD.Title = "Images";
                   FD.Filter = "Png Images| *.png";
                   FD.ShowDialog();
                   if (FD.FileName.ToString() != "")
                   {
                       pngImage.ImageLocation = FD.SafeFileName.ToString();
                       img = new Bitmap(FD.SafeFileName.ToString());
                   }//end if
Posted
Updated 26-Nov-12 23:48pm
v4
Comments
[no name] 27-Nov-12 10:24am    
i have tested your code in my window 7 and i work fine ..there is no issue with your code

OpenFileDialog FD = new OpenFileDialog();

if(FD.ShowDialog()==DialogResult.OK)
{
FD.Title = "Images";
                   FD.Filter = "Png Images| *.png";
                   FD.ShowDialog();
                   if (FD.FileName.ToString() != "")
                   {
                       pngImage.ImageLocation = FD.SafeFileName.ToString();
                       img = new Bitmap(FD.SafeFileName.ToString());
                   }//end if
}
 
Share this answer
 
Where is that code called? Is it somewhere in a Form_Load or Form_Shown event - under some circumstances, exceptions thrown there are not shown.
Can you debug the program step by step downto the ShowDialog() call?
 
Share this answer
 
C#
FD.FileOk += new CancelEventHandler(openFileDialog1_FileOk);

private void openFileDialog1_FileOk(object sender, 
		System.ComponentModel.CancelEventArgs e)
{
 if (FD.FileName.ToString() != "")
                    {
                        pngImage.ImageLocation = FD.SafeFileName.ToString();
                        img = new Bitmap(FD.SafeFileName.ToString());
                    }//end if
}
 
Share this answer
 
v2
C#
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
  //openFileDialog1.FileName
}


This one works for me in win7
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900