首页 > 解决方案 > vb.net 访问文件夹被拒绝

问题描述

我到处搜索这个错误,将程序的清单文件更改为以管理员身份运行,但没有任何改变,我为自己制作了一个程序来获取视频流链接,我将它的第一部分放在 textbox1 中,第二部分放在textbox2 这些放在一起并添加了剧集的编号,但是当我尝试保存包含所有链接的 txt 文件时,我无法保存它,因为访问被拒绝。

Imports System
Imports System.IO
Imports System.Text

Public Class Form1
    Dim l1 As String
    Dim l2 As String
    Dim ep As Integer
    Dim nEp As Integer
    Dim testo As String
    Dim path As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label4.Text = "Link:" & vbCrLf
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        l1 = CStr(TextBox1.Text)
        l2 = CStr(TextBox2.Text)
        nEp = CInt(TextBox3.Text)

        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""

        If l1 <> "" And l2 <> "" And IsNumeric(nEp) Then
            If ep <= 9 Then
                For ep = 0 To 9
                    Label4.Text = Label4.Text + l1 & "0" & ep & l2 & vbCrLf
                Next
                If ep > 9 Then
                    For ep = 10 To nEp
                        Label4.Text = Label4.Text + l1 & ep & l2 & vbCrLf
                    Next
                    testo = Label4.Text
                    FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.DesktopDirectory
                    If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                        path = FolderBrowserDialog1.SelectedPath
                    End If
                    File.Create(FolderBrowserDialog1.SelectedPath).Dispose()
                    File.WriteAllText(FolderBrowserDialog1.SelectedPath, testo)
                End If
                End If
        Else
            MsgBox("Inserisci i dati correttamente!")
        End If


    End Sub

End Class

标签: vb.netforms

解决方案


我设法让它工作,但如果我想再次使用它而不关闭表单,按钮不会做任何事情。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    l1 = CStr(TextBox1.Text)
    l2 = CStr(TextBox2.Text)
    nEp = CInt(TextBox3.Text)
    nomeFile = CStr(TextBox4.Text)

    If l1 <> "" And l2 <> "" And IsNumeric(nEp) Then
        If nomeFile <> "" Then
            If ep <= 9 Then
                For ep = 0 To 9
                    Label4.Text = Label4.Text + l1 & "0" & ep & l2 & vbCrLf
                Next
                If ep > 9 Then
                    For ep = 10 To nEp
                        Label4.Text = Label4.Text + l1 & ep & l2 & vbCrLf
                    Next
                    testo = Label4.Text
                    If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                        path = FolderBrowserDialog1.SelectedPath + "\" + nomeFile + ".txt"
                    End If
                    File.Create(path).Dispose()
                    File.WriteAllText(path, testo)
                    MsgBox("File created")

                    TextBox1.Text = ""
                    TextBox2.Text = ""
                    TextBox3.Text = ""
                    TextBox4.Text = ""
                    Label4.Text = ""
                End If
            End If
        Else
            MsgBox("File name missing")
        End If
    Else
        MsgBox("You need to fill the requested inputs!")
    End If


End Sub

推荐阅读