asp.net C # File Upload

Source: Internet
Author: User
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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.