sayso36
06-19-2008, 10:19 PM
Hello,
I'm trying to create webpage for file upload on server. However I keep getting the following error. Could someone please tell me step-by-step how to solve this problem(grant permissions). This is really frustrating.
http://ectweb2.cs.depaul.edu/sdesai8/uploadNsave.aspx
Error saving E:\ectserver\sdesai8\UploadedImages\bb
System.UnauthorizedAccessException: Access to the path 'E:\ectserver\sdesai8\UploadedImages\bb' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at ASP.uploadnsave_aspx.btnUploadTheFile_Click(Object Source, EventArgs evArgs) in e:\ectserver\sdesai8\uploadNsave.aspx:line 27
here's my code:
<% @Page Language="C#" %>
<html>
<head>
<title>File upload in ASP.NET</title>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<script language="C#" runat="server">
void Page_Load()
{
Response.Write(Server.MapPath("./UploadedImages").ToString());
}
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
string strFileNameOnServer = txtServername.Value;
//string strBaseLocation = ("c:/csc224/");
string strBaseLocation = Server.MapPath("./UploadedImages/");
if (strFileNameOnServer == "")
{
txtOutput.InnerHtml = "Error - a file name must be specified.";
return;
}
if (uplTheFile.PostedFile != null)
{
try
{
uplTheFile.PostedFile.SaveAs(strBaseLocation + strFileNameOnServer);
txtOutput.InnerHtml = "File <b>" +
strBaseLocation+strFileNameOnServer+"</b> uploaded successfully";
}
catch (Exception e)
{
txtOutput.InnerHtml = "Error saving <b>" +
strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
}
}
}
</script>
<table>
<form enctype="multipart/form-data" runat="server">
<tr>
<td>Select file:</td>
<td><input id="uplTheFile" type=file runat="server"></td>
</tr>
<tr>
<td>Name on server:</td>
<td><input id="txtServername" type="text" runat="server"></td>
</tr>
<tr>
<td colspan="2">
<input type=button id="btnUploadTheFile" value="Upload"
OnServerClick="btnUploadTheFile_Click" runat="server">
</td>
</tr>
</form>
</table>
<span id=txtOutput style="font: 8pt verdana;" runat="server" />
</body>
</html>
Thank you guys!!!
I'm trying to create webpage for file upload on server. However I keep getting the following error. Could someone please tell me step-by-step how to solve this problem(grant permissions). This is really frustrating.
http://ectweb2.cs.depaul.edu/sdesai8/uploadNsave.aspx
Error saving E:\ectserver\sdesai8\UploadedImages\bb
System.UnauthorizedAccessException: Access to the path 'E:\ectserver\sdesai8\UploadedImages\bb' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at ASP.uploadnsave_aspx.btnUploadTheFile_Click(Object Source, EventArgs evArgs) in e:\ectserver\sdesai8\uploadNsave.aspx:line 27
here's my code:
<% @Page Language="C#" %>
<html>
<head>
<title>File upload in ASP.NET</title>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<script language="C#" runat="server">
void Page_Load()
{
Response.Write(Server.MapPath("./UploadedImages").ToString());
}
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
string strFileNameOnServer = txtServername.Value;
//string strBaseLocation = ("c:/csc224/");
string strBaseLocation = Server.MapPath("./UploadedImages/");
if (strFileNameOnServer == "")
{
txtOutput.InnerHtml = "Error - a file name must be specified.";
return;
}
if (uplTheFile.PostedFile != null)
{
try
{
uplTheFile.PostedFile.SaveAs(strBaseLocation + strFileNameOnServer);
txtOutput.InnerHtml = "File <b>" +
strBaseLocation+strFileNameOnServer+"</b> uploaded successfully";
}
catch (Exception e)
{
txtOutput.InnerHtml = "Error saving <b>" +
strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
}
}
}
</script>
<table>
<form enctype="multipart/form-data" runat="server">
<tr>
<td>Select file:</td>
<td><input id="uplTheFile" type=file runat="server"></td>
</tr>
<tr>
<td>Name on server:</td>
<td><input id="txtServername" type="text" runat="server"></td>
</tr>
<tr>
<td colspan="2">
<input type=button id="btnUploadTheFile" value="Upload"
OnServerClick="btnUploadTheFile_Click" runat="server">
</td>
</tr>
</form>
</table>
<span id=txtOutput style="font: 8pt verdana;" runat="server" />
</body>
</html>
Thank you guys!!!