vb.net - 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
解决方案
我设法让它工作,但如果我想再次使用它而不关闭表单,按钮不会做任何事情。
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
推荐阅读
- r - 如何使用 R 绘制带有自定义标题的两列时间序列网格?
- angular - 如何在 ngx-bootstrap typeahead 中检索对象的键?
- python - 哪里错了?我尝试编写一个将矩阵相乘并出现“NonType”错误的程序
- elasticsearch - 英国邮政编码的 Elasticsearch 映射,能够处理间距和大写
- firebase - 如何在 cloudflare 上使用 DNS 将 Firebase authDomain url 更改为自定义域
- python - 使用 pyparsing 使用 `delimitedList` 设置最大出现次数
- c# - 避免 C# 代码中多个控制器的冗余
- flutter - 如何在颤振(飞镖)中解决未来?
- r-caret - caret 中的 blassoAveraged 模型真的是岭模型吗?
- python - 从嵌套列表中删除负元素并对列表进行平方而不使用循环