Cannot Upload File on WebApp Access Denied

user9892317

I built a web app that allows users to upload a file to a folder. I was given the following exception.

System.UnauthorizedAccessException: Access to the path 'C:\Users\NAME\Documents\Uploads' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)'

I changed the sharing permissions on this file to allow everyone to read and change the file and I continue to run into the exception.

My Code Is Here:

<%@ Page Language="C#" %>
<script runat="server">

    void SubmitButton_Click(Object sender, EventArgs e) {
       if (File1.PostedFile != null) {
          try {
             File1.PostedFile.SaveAs("C:\\Users\\NAME\\Documents\\Uploads");
             Span1.InnerHtml = "Upload Successful!";
          }
          catch (Exception ex) {
             Span1.InnerHtml = "Error saving file <b>C:\\" +
                File1.Value + "</b><br>" + ex.ToString();
          }
       }
    } 

</script>
<html>
<head>
</head>
<body>
    <form runat="server" enctype="multipart/form-data">
        Select a file to upload:<br />
        <input type="file" id="File1" runat="Server">
        <p>
        <input type="submit" id="Submit1" runat="Server" 
         value="Upload File" OnServerClick="SubmitButton_Click">
        <p>
        <span id="Span1" runat="Server" />
    </form>
    </span>
    <p>
</body>
</html>

Compiler

void SubmitButton_Click(Object sender, EventArgs e) {
   if (File1.PostedFile != null) {
      try {

     File1.PostedFile.SaveAs(HttpContext.Current.Server.MapPath("/Uploads"));
         Span1.InnerHtml = "Upload Successful!";
      }
      catch (Exception ex) {
         Span1.InnerHtml = "Error saving file <b>C:\\" +
            File1.Value + "</b><br>" + ex.ToString();
      }
   }
} 

In the SaveAs Method , you need to tell the application to use Server.MapPath method to use the path in your application and not on the absolute path.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot create file, access is denied

From Dev

Cannot access the file: Permission denied - Virtualbox

From Dev

Postgres cannot open CSV file for read access: Permission denied

From Dev

Cannot create file "c:\User\...\Appdata\Roaming...". Access is denied

From Dev

Sudo chmod +x leads to "cannot access [file] permission denied"

From Dev

Error in file(file, "rt") : cannot open the connection - cannot open file 'specdata' access denied

From Dev

Deleting file, but is access denied

From Dev

File access is denied

From Dev

File access is denied

From Dev

File copy access denied

From Dev

Access denied to delete file

From Dev

Ruby S3 "Access Denied" error when calling upload_file with ACL

From Dev

Upload file from webapp with selenium webDriver

From Dev

Upload a file in a separate thread in a java webapp

From Dev

WebApi File Read Access is Denied

From Dev

Access denied when deleting file

From Dev

Cannot upload file

From Dev

Cannot upload a file in proctractor

From Dev

Cannot upload a file with jersey

From Dev

Wordpress - Cannot upload file

From Dev

Cannot upload file to form

From Dev

Cannot get SonarQube Scanner for MSBuild 2.2.0.24 working : Access to the path is denied on .cs file

From Dev

Errno 13 Permission denied Django Upload File

From Dev

OSError [Errno 13] Permission denied on file upload

From Dev

Spring MVC - Cannot create file at webapp/resources/

From Dev

Spring MVC - Cannot create file at webapp/resources/

From Dev

ls: cannot access .gvfs: Permission denied

From Dev

Cannot stop Avira Antivirus service: access denied

From Dev

Computer Browser service cannot start, "Access Denied"

Related Related

HotTag

Archive