In my web application I have to move a file from the user computer to the server. I have to use an ascx component to do this.
Here is the code:
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
So when the source file is in a folder like "MyDocuments" or "MyPictures" or any sub folder inside the "User" folder i got the access denied error.
When the source file is in folders like "C:\" or "C:\ProgramFiles" I don't get this error.
Usually you're getting an error in ASP.NET because an account your application is running under don't have appropriate permissions.
But what you've described is file uploading. Server-side code has no access to client machine file system, this is impossible. Client have to upload it from a location it wish. Use <asp:FileUpload>
control for this purpose.