ASP UpLoad Not Working

Joined
Aug 29, 2008
Messages
1
Reaction score
0
I have created simple ASP uploads to try. I cant seem to get it to work, i have included the code as well.

ASPX Page-
<%@ register tagprefix="era" tagname="upload" src="fileUpload.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<h2>File-Upload User Control Sample</h2>
<hr />

<era:upload runat="server" submitText="Send File" uploadFolder="Server.MapPath"/>


</body>
</html>


ASCX Page-
<%@ control description="ASP.NET file upload user control" %>

<script language="c#" runat="server">

// public attributes for the user control
public string uploadText="Upload file:";
public string saveText="Save as:";
public string statusText="Status:";
public string submitText="Upload File";
public string uploadFolder="c:\\upload";

private void Page_Load(object o, EventArgs e) {

// move attributes into the form
upSpan.InnerText=uploadText;
saveSpan.InnerText=saveText;
statusSpan.InnerText=statusText;
uploadBtn.Value=submitText;
}

private void uploadBtn_Click(object o, EventArgs e) {

// make sure there is a file to upload
if (savename.Value == "") {
status.InnerHtml = "Missing a 'save as' name.";
return;
}

// try save the file to the web server
if (filename.PostedFile != null) {
string sPath=uploadFolder;

//build file info for display
string sFileInfo =
"<br>FileName: "+
filename.PostedFile.FileName+
"<br>ContentType: "+
filename.PostedFile.ContentType+
"<br>ContentLength: "+
filename.PostedFile.ContentLength.ToString();

try {
filename.PostedFile.SaveAs(sPath+savename.Value);
status.InnerHtml = "File uploaded successfully."+sFileInfo;
}
catch (Exception exc) {
status.InnerHtml = "Error saving file"+
sFileInfo+"<br>"+e.ToString();
}
}
}


</script>

<!-- create special form for uploading files -->
<form enctype="multipart/form-data" runat="server">
<table width="400" cellpadding="4" bgcolor="silver">
<tr>
<td valign="top" width="100">
<span id="upSpan" runat="server"/>
</td>
<td valign="top" >
<input type="file" id="filename" runat="server" />
</td>
</tr>
<tr>
<td valign="top" >
<span id="saveSpan" runat="server"/>
</td>
<td valign="top" >
<input type="text" id="savename" runat="server" />
</td>
</tr>
<tr>
<td valign="top" >
<span id="statusSpan" runat="server"/>
</td>
<td valign="top" >
<span id="status" runat="server" />
</td>
</tr>
<tr>
<td valign="top" >
&nbsp;
</td>
<td valign="top" >
<input type="button" id="uploadBtn"
OnServerClick="uploadBtn_Click"
runat="server" />
</td>
</tr>
</table>
</form>


The Error I get it this on the page-
--------------------------------------------------------------------------------

Status: Error saving file
FileName: C:\Documents and Settings\rarnett\Desktop\log.txt
ContentType: text/plain
ContentLength: 7945
System.EventArgs

Any Help Please.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top