2010-08-17 8 views
6

here의 기본 파일 대화 상자 예제를 사용하고 있는데 '확인'오류가 발생하고 이유를 모르겠습니다.'System.Nullable <bool>'에 'OK'에 대한 정의가 없습니다.

오류 'System.Nullable'에 'OK'에 대한 정의가없고 'System.Nullable'유형의 첫 번째 인수를 허용하는 확장 메서드가 없습니다 (using 지시문이 누락 되었습니까? 당신이 DialogResult라는 지역의 특성을 가지고있는 것처럼 또는 어셈블리 참조가?)

private void button1_Click(object sender, System.EventArgs e) 
{ 
    Stream myStream = null; 
    OpenFileDialog openFileDialog1 = new OpenFileDialog(); 

    openFileDialog1.InitialDirectory = "c:\\" ; 
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; 
    openFileDialog1.FilterIndex = 2 ; 
    openFileDialog1.RestoreDirectory = true ; 

    if(openFileDialog1.ShowDialog() == DialogResult.OK) 
    { 
     try 
     { 
      if ((myStream = openFileDialog1.OpenFile()) != null) 
      { 
       using (myStream) 
       { 
        // Insert code to read the stream here. 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); 
     } 
    } 
} 
+0

당신의 OpenFileDialog를이 무엇 조립입니다? –

+0

이 작품은 좀 더 구체적인 수 있습니까? 오류는 아마도 여기에 없습니다 ... – jeroenh

답변

16

.NET Framework에는 OpenFileDialog의 두 가지 버전이 있습니다 (WinForms oneWPF one). WPF를 사용하는 것처럼 보입니다. 사실 Nullable<bool> 값을 OpenFile에서 반환합니다. WinForm 버전은 DialogResult 값을 반환합니다. 이는 예상 한 것 같습니다.

+0

링크 된 버전은 WIN32 버전입니다. 나는 WPF에 특정한 것이 있다고 생각하지 않는다. – pug

+1

@pug 해당 클래스는 WPF의 핵심 어셈블리 중 하나 인 PresentationFramework 어셈블리에 정의되어 있습니다. –

8

소리가 난다. 대신 System.Windows.Forms.DialogResult.OK을 사용해보십시오.

+0

이것은 나를 위해 일했습니다. 고맙습니다!!!!! – jjones150

1

System.Windows.ControlsShowDialog을 사용하려고합니다. System.Windows.Forms

등으로 통화가 명시 적으로 만드는 시도 :

System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); 
관련 문제