我正在尝试将文件上传到新创建的目录,我设法创建它但无法将文件放在那里,因为访问被拒绝,我怎样才能允许访问该目录?
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
<asp:Label ID="Label1" runat="server" Text="Upload Status"></asp:Label>
VB.NET
Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) 处理 LinkButton1.ClickIf FileUpload1.HasFile Then 尝试 暗淡文件 = FileUpload1.PostedFile.ContentType 暗淡扩展为字符串 = Path.GetExtension(FileUpload1.FileName) 如果扩展 = ".jpeg" 或者其他扩展 = ".jpg" 那么
If FileUpload1.PostedFile.ContentLength > 2097152 Then Label1.Text = "File Too Big" Else Dim directoryPath As String = Server.MapPath("~/bussnisses") If Not Directory.Exists(directoryPath) Then Directory.CreateDirectory(directoryPath) FileUpload1.SaveAs(directoryPath) Else FileUpload1.SaveAs(directoryPath) End If Label1.Text = "complete" End If Else Label1.Text = " jpeg or jpg" End If Catch ex As Exception End Try End If End Sub