1

在我的 Web 应用程序中,我必须将文件从用户计算机移动到服务器。我必须使用 ascx 组件来执行此操作。

这是代码:

Private Function FileReplciate(ByRef FilePath As String)
     'FilePath  is the full file path e.g C:/Program Files/file.txt

      ' Create an id to hide the original file name (for security)

       Dim id = New Guid;

      Try

      'Here I move the file using File.Move()  here is the error
       File.Move(FilePath, Server.MapPath("temp\" & id.ToString))

      Catch ex As exception

      End Try

End Function

因此,当源文件位于“MyDocuments”或“MyPictures”之类的文件夹或“User”文件夹内的任何子文件夹中时,我收到拒绝访问错误。

当源文件位于“C:\”或“C:\ProgramFiles”等文件夹中时,我不会收到此错误。

4

1 回答 1

2

通常你会在 ASP.NET 中遇到错误,因为运行你的应用程序的帐户没有适当的权限。

但是您所描述的是文件上传。服务器端代码无法访问客户端机器文件系统,这是不可能的。客户必须从它希望的位置上传它。<asp:FileUpload>为此目的使用控制。

于 2012-10-11T17:51:07.617 回答