以下为源程序,但一上传就出现"Access to the path "E:\www\qtime\db_file" is denied."
这个文件夹我设置权限可以写入呀,另我的机器分区格式为FAT32,和这个有关系吗?
<%@ Page language="c#" %>
<html>
<head>
<title>文件上传</title>
<style type=text/css>
td {font-size:12px}
.big {font-size:14px}
</style>
</head>
<body>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
lblError.Text = "";
} private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
if (!uploadFile.Value.ToLower().EndsWith(".jpg") && !uploadFile.Value.ToLower().EndsWith(".gif"))
throw new Exception("只能上传图片文件。");
//判断上传文件的类型
HttpPostedFile postFile = uploadFile.PostedFile;
//调用标准类库,方法
int contentLength = postFile.ContentLength;
if (contentLength > 512*1024)
throw new Exception("不能上传大于 512K 的文件。");
//判断上传文件的大小
string fileName = postFile.FileName;
//fileName 是您刚刚上传的文件名
fileName=fileName.Substring(fileName.LastIndexOf("")+1);
postFile.SaveAs(Request.PhysicalApplicationPath+"\\db_file" + fileName);
//保存文件
lblError.Text = "上传成功!<a href='" + fileName + "' target='_blank'>查看</a> 刚刚上传的文件。";
}
catch(Exception ex)
{ lblError.Text = ex.Message;
//当出现错误时,打印出错信息
}
}
</script> <form id="UploadForm" method="post" enctype="multipart/form-data" runat="server">
<table width="75%" align=center cellpadding=4 cellspacing=4>
<tr>
<td>
ASP.NET 示例程序
</td>
</tr>
<tr height="1" bgcolor="red">
<td>
</td>
</tr>
<tr>
<td align=center>
<b class="big">文件上传</b>
</td>
</tr>
<tr>
<td align="center">
<input type="file" id="uploadFile" runat="server" />
<asp:Button ID="btnUpload" Text="上传" Runat="server" OnClick="btnUpload_Click"></asp:Button>
</td>
</tr>
<tr>
<td align=center><asp:Label id="lblError" runat="server" ForeColor="Red" /></td>
</tr>
</table>
</form>
</body>
</html>
这个文件夹我设置权限可以写入呀,另我的机器分区格式为FAT32,和这个有关系吗?
<%@ Page language="c#" %>
<html>
<head>
<title>文件上传</title>
<style type=text/css>
td {font-size:12px}
.big {font-size:14px}
</style>
</head>
<body>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
lblError.Text = "";
} private void btnUpload_Click(object sender, System.EventArgs e)
{
try
{
if (!uploadFile.Value.ToLower().EndsWith(".jpg") && !uploadFile.Value.ToLower().EndsWith(".gif"))
throw new Exception("只能上传图片文件。");
//判断上传文件的类型
HttpPostedFile postFile = uploadFile.PostedFile;
//调用标准类库,方法
int contentLength = postFile.ContentLength;
if (contentLength > 512*1024)
throw new Exception("不能上传大于 512K 的文件。");
//判断上传文件的大小
string fileName = postFile.FileName;
//fileName 是您刚刚上传的文件名
fileName=fileName.Substring(fileName.LastIndexOf("")+1);
postFile.SaveAs(Request.PhysicalApplicationPath+"\\db_file" + fileName);
//保存文件
lblError.Text = "上传成功!<a href='" + fileName + "' target='_blank'>查看</a> 刚刚上传的文件。";
}
catch(Exception ex)
{ lblError.Text = ex.Message;
//当出现错误时,打印出错信息
}
}
</script> <form id="UploadForm" method="post" enctype="multipart/form-data" runat="server">
<table width="75%" align=center cellpadding=4 cellspacing=4>
<tr>
<td>
ASP.NET 示例程序
</td>
</tr>
<tr height="1" bgcolor="red">
<td>
</td>
</tr>
<tr>
<td align=center>
<b class="big">文件上传</b>
</td>
</tr>
<tr>
<td align="center">
<input type="file" id="uploadFile" runat="server" />
<asp:Button ID="btnUpload" Text="上传" Runat="server" OnClick="btnUpload_Click"></asp:Button>
</td>
</tr>
<tr>
<td align=center><asp:Label id="lblError" runat="server" ForeColor="Red" /></td>
</tr>
</table>
</form>
</body>
</html>
有这个路径吗???
管你什么格式的分区,文件夹也要有写的权限。。
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path "C:\qtime\db_file" is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Server.MapPath
改成:
postFile.SaveAs(Server.MapPath("\\根目录\\存上传文件的路径\\"+fileName));
Access to the path "C:\qtime\db_file" is denied.
{
string strFileName;
strFileName = System.IO.Path.GetFileName(fileup.PostedFile.FileName.ToString());
Response.Write(strFileName); if (fileup.PostedFile != null)
{
try
{
fileup.PostedFile.SaveAs(Server.MapPath("../up_pic/") + strFileName);
Response.Write("文件上传成功");
}
catch(System.Exception Ex)
{
Response.Write(Ex.Message.ToString().Trim());
}
}
}