Asp.net| Upload Exception Details: system.unauthorizedaccessexception: On Path "C:\Inetpub\spatial\csk\Communities\Common\Images\ Access to Htmltextboxuserimages\logo.gif "was denied.
ASP.net is not authorized to access the requested resource. Consider granting the ASP.NET request identity access to this resource. ASP.net has a base process identity that is used when the application has no impersonation (typically, on IIS 5, on IIS 6 for network services). If the application is/> impersonation through <identity impersonate= "true", the identity will be anonymous (usually IUSR_machinename) or authenticated request user.
To grant ASP.net write access to a file, right-click the file in Explorer, select Properties, and then select the Security tab. Click Add to add the appropriate user or group. Highlight the ASP.net account, and select the box that corresponds to the required access rights.
SOURCE Error:
<%--
Upload.aspx
This is an upload file, from which we can see the advantages of ASP.net, the previous need for control to complete the program, now only need a few lines of code can be easily completed.
--%>
<%@ Import namespace= "System.IO"%>
<%@ page language= "C #" debug= "true" codepage= "936"%>
<title> file Upload, aspcool.com </title>
<script language= "C #" runat= "Server" >
public void UploadFile (object sender, EventArgs E)
{
if (myfile.postedfile!=null)
{
Define some variables
String nam = MyFile.PostedFile.FileName;
int i= Nam. LastIndexOf ("\");
String Newnm =nam. Substring (i);
Change the "c:\\" below to the address you want to save.
MyFile.PostedFile.SaveAs ("c:\\inetpub\\spatial\\csk\\communities\\common\\images\\htmltextboxuserimages\\" + NEWNM);
Gets the various attributes of the uploaded file.
FName. Text=myfile.postedfile.filename;
Fenc. Text=myfile.postedfile.contenttype;
Fsize. Text=myfile.postedfile.contentlength.tostring ();
}
}
</script>
<body>
<center>
<form id= "Uploderform" method= "post" action= "upload.aspx" enctype= "Multipart/form-data" runat= "Server" >
<table border= "1" cellspacing= "0" cellpadding= "0" >
<tr> <td><tr><td>
<input type= "File" id= "MyFile" runat= "Server" >
</td></tr>
<tr><td>
<input type= "button" value= "Upload" onserverclick= "UploadFile" runat= "Server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border= "1" cellspacing= "0" >
<tr><td><b> Documents </b></td>
<td> </td>
</tr>
<tr>
<td> file name:</td>
<td><asp:label id= "fname" text= "" runat= "Server"/></td></tr>
<tr>
<td> File Type:</td>
<td><asp:label id= "Fenc" runat= "Server"/></td></tr>
<tr>
<td> file Size:(in bytes) </td>
<td><asp:label id= "fsize" runat= "Server"/></td></tr>
</table>
<br>
<br>
<br>
</center>
</body>