Click here to Skip to main content
11,715,491 members (87,314 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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

OpenFileDialog FD = new OpenFileDialog();

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 26-Nov-12 23:39pm
bmw318mt1.4K
Edited 26-Nov-12 23:48pm
v4
Comments
Lakhan Aanjana at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 518
1 Richard MacCutchan 300
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100