Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“保存”按钮不保存在.txt文件Visual Basic.NET中_.net_Visual Studio 2013 - Fatal编程技术网

“保存”按钮不保存在.txt文件Visual Basic.NET中

“保存”按钮不保存在.txt文件Visual Basic.NET中,.net,visual-studio-2013,.net,Visual Studio 2013,上面的代码是用来将我的数独游戏保存到一个.txt文件中的 我遇到的问题是,每当我单击“保存”按钮时,一切都正常,直到它没有将文件保存为.txt文件为止。它只是将其保存为“文件” 有人知道这是从哪里来的吗?我该如何解决这个问题 注意:我已尝试将SaveFileDialog1.filter仅设置为txt文件,但没有帮助。 提前感谢。过滤器对保存的文件类型没有任何影响,只对对话框中显示的文件类型有影响(类似于打开)。第一次创建文件时,实际扩展名“.txt”需要与文件一起保存。这就是windows知道该

上面的代码是用来将我的数独游戏保存到一个.txt文件中的

我遇到的问题是,每当我单击“保存”按钮时,一切都正常,直到它没有将文件保存为.txt文件为止。它只是将其保存为“文件”

有人知道这是从哪里来的吗?我该如何解决这个问题

注意:我已尝试将SaveFileDialog1.filter仅设置为txt文件,但没有帮助。


提前感谢。

过滤器对保存的文件类型没有任何影响,只对对话框中显示的文件类型有影响(类似于打开)。第一次创建文件时,实际扩展名“.txt”需要与文件一起保存。这就是windows知道该文件是文本文件的原因。否则,如果您只是将其保存为“MySudoku”,它将不包括文件扩展名

尝试使用defaultext属性

Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
    Dim strLineFromSave As String
              'This method below returns a String of 81 characters long.'
    strLineFromSave = grid.udsSave()
    SaveFileDialog1.Filter = "TXT Files (*.txt*)|*.txt*"
    If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(SaveFileDialog1.FileName)
            'For loop to write a line every 9 characters, so you get a 9x9 grid.'
        For intCounter As Integer = 0 To (strLineFromSave.Length - 1) Step 9
            Dim strTemp = strLineFromSave.Substring(intCounter, 9)
            sw.WriteLine(strTemp)
        Next
        sw.Close()
    End If
End Sub

非常感谢你!这成功了!只要这一页允许我:D,我就会标记为答案
SaveFileDialog1.DefaultExt = "txt"