jbezweb
02-18-2005, 06:14 PM
I am having trouble uploading a file. I keep getting this error:
CS0118: 'System.Web.UI.Page.Request' denotes a 'property' where a 'class' was expected
If i remove the variable site and the request.querystring and use a static path it works fine but i need that variable, which is passed by a querystring, to determine what folder the file is to go to.
Any ideas? My code is below.
thx,
<%@ Page Language="C#" Debug="True"%>
<html>
<head>
<title>File upload in ASP.NET</title>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<script language="C#" runat="server">
string site = Request.QueryString["site"];
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
string strFileNameOnServer = txtServername.Value;
string strBaseLocation = Server.MapPath("/iMasterengine/sites/"+site+"/siteadmin/images/");
if ("" == strFileNameOnServer)
{
txtOutput.InnerHtml = "Error - a file name must be specified.";
return;
}
if (null != uplTheFile.PostedFile)
{
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>
CS0118: 'System.Web.UI.Page.Request' denotes a 'property' where a 'class' was expected
If i remove the variable site and the request.querystring and use a static path it works fine but i need that variable, which is passed by a querystring, to determine what folder the file is to go to.
Any ideas? My code is below.
thx,
<%@ Page Language="C#" Debug="True"%>
<html>
<head>
<title>File upload in ASP.NET</title>
</head>
<body bgcolor="#ffffff" style="font:8pt verdana;">
<script language="C#" runat="server">
string site = Request.QueryString["site"];
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
string strFileNameOnServer = txtServername.Value;
string strBaseLocation = Server.MapPath("/iMasterengine/sites/"+site+"/siteadmin/images/");
if ("" == strFileNameOnServer)
{
txtOutput.InnerHtml = "Error - a file name must be specified.";
return;
}
if (null != uplTheFile.PostedFile)
{
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>