“保存类型”未显示

时间:2011-10-19 13:01:30

标签: vb.net

好的,我正在尝试保存文件,我想将用户限制为* .txt和。我想制作默认的* .txt。该代码用于保存文件,但我没有看到“保存类型”选项有任何选择,默认的.txt扩展名不在文件名字段中。我错过了什么或做错了什么?

Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
    'Write the converted string to the file
    Dim FileToSaveAs As String = SaveFileDialog1.FileName

    Dim FileWriter As New StreamWriter(FileToSaveAs)
    With SaveFileDialog1
        .DefaultExt = ".txt"
        .FilterIndex = 2
        .RestoreDirectory = True
        .Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
        .InitialDirectory = "C:\AppTemp"
        .Title = "Save processed file"
    End With

    FileWriter.Write(TextOut)
    FileWriter.Close()
End Sub

1 个答案:

答案 0 :(得分:0)

在显示之前,您必须设置SaveFileDialog参数 试试这个:

public sub SaveFile
    With SaveFileDialog1
        .DefaultExt = ".txt"
        .FilterIndex = 1
        .RestoreDirectory = True
        .Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"
        .InitialDirectory = "C:\AppTemp"
        .Title = "Save processed file"
        If .ShowDialog() = DialogResult.OK then
            Dim FileWriter As New StreamWriter(.Filename)
            FileWriter.Write(TextOut)
            FileWriter.Close()
        End If
    End With
End Sub