简体   繁体   English

File.create 没有显示错误但没有创建文件?

[英]File.create shows no errors but doesnt create file?

I'm trying to copy a file from an external drive by reading its contents, creating a new file elsewhere and writing the contents into it.我正在尝试通过读取文件内容、在别处创建新文件并将内容写入其中来从外部驱动器复制文件。
My code shows no errors (using MSV) but when I try to 'download' the file, it completes the code but no file is created.我的代码没有显示任何错误(使用 MSV),但是当我尝试“下载”文件时,它完成了代码但没有创建文件。
Can anyone help?谁能帮忙?

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim FileReader As String
        FileReader = My.Computer.FileSystem.ReadAllText(Label32.Text)
        Dim fbd As FolderBrowserDialog = New FolderBrowserDialog
        Dim DownloadLocation As String
        If fbd.ShowDialog() <> DialogResult.Cancel Then
            DownloadLocation = fbd.SelectedPath
            File.Create(fbd.SelectedPath & "pandora speedsign log.txt").Dispose()
            File.WriteAllText(fbd.SelectedPath & "pandora speedsign log.txt", FileReader)
            MessageBox.Show("success!!")
        End If
        'File.Create("C:\Users\%UserProfile%\Downloads" & DownloadFileDate & ".txt")
        'File.WriteAllText("C:\Users\%USERPROFILE%\Downloads" & DownloadFileDate & ".txt", FileReader)
  End Sub

I've been looking for different ways of creating the file, different ways of writing the file but nothing seems to work.我一直在寻找不同的创建文件的方式,不同的写入文件的方式,但似乎没有任何效果。

We can significantly simplify the code like this:我们可以像这样显着简化代码:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim fbd As New FolderBrowserDialog()
    If fbd.ShowDialog() <> DialogResult.Ok Then Exit Sub

    Dim outputPath As String = IO.Path.Combine(fbd.SelectedPath, "pandora speedsign log.txt")
    IO.File.Copy(Label32.Text, outputPath)
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM