Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
sYnced

Verificar OpenFileDialog

Recommended Posts

sYnced

Alguém me pode dizer como manter sempre o openfile dialog aberto ?

o meu código é este

               MessageBox.Show("Introduza o Directório do hl.exe");
               DialogResult result = openFileDialog1.ShowDialog();
               bool folder = false;
               bool pt = true;
               while (folder = false)
               {
                   if (result == DialogResult.OK) // Test result.
                   {
                       string directoryPath = Path.GetDirectoryName(openFileDialog1.FileName);
                       if (!File.Exists(directoryPath + @"\hl.exe"))
                       {
                           folder = false;
                       }
                       else
                       {
                           folder = true;
                       }
                       if (!File.Exists(directoryPath + @"\cstrike_portuguese"))
                       {
                           folder = false;
                           pt = false;
                       }
                       else
                       {
                           folder = true;
                       }
                       if (folder = false)
                       {
                           MessageBox.Show("Introduza a pasta do hl.exe");
                           result = openFileDialog1.ShowDialog();
                       }
                       else
                       {
                           FileStream fs = File.Create(@"win7.txt");
                           StreamWriter m_streamWriter = new StreamWriter(fs);
                           // Write to the file using StreamWriter class
                           m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
                           if (pt == true)
                           {
                               m_streamWriter.Write(directoryPath + @"\cstrike_portuguese");
                           }
                           else
                           {
                               m_streamWriter.Write(directoryPath + @"\cstrike");
                           }
                           m_streamWriter.Flush();
                           // Read from the file using StreamReader class
                           // StreamReader m_streamReader = new StreamReader(fs);
                           // string str = m_streamReader.ReadLine();
                       }
                   }

Edited by thoga31
GeSHi

Share this post


Link to post
Share on other sites
rumbafum

Acho que podes usar o evento FileOk para isso. Se o ficheiro não for válido fazes set da propriedade Cancel para true e o OpenFileDialog fica aberto

  • Vote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.