What am I doing wrong here with file uploading?

J

jm

Microsoft KB Article:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;323246

I took the code and copied and pasted it in the my two files.
Everytime I run it, I get:

Parser Error Message: Could not load type 'CSharpUpload.WebForm1'.

Line 1: <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
Inherits="CSharpUpload.WebForm1" %>

What obvious thing am I missing? Is this not a copy and paste type
thing? Incidentally, I get the same thing with the vb.net version, so
I must be doing something elementary wrong here. Thank you.

Sorry, but here is their code, if you don't want to click the link:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
Inherits="CSharpUpload.WebForm1" %>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" enctype="multipart/form-data"
runat="server">
<INPUT type=file id=File1 name=File1 runat="server" >
<br>
<input type="submit" id="Submit1" value="Upload" runat="server"
NAME="Submit1">
</form>


</body>
</HTML>


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CSharpUpload
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Submit1.ServerClick += new
System.EventHandler(this.Submit1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Submit1_ServerClick(object sender, System.EventArgs e)
{
if( ( File1.PostedFile != null ) && ( File1.PostedFile.ContentLength
{
string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;
try
{
File1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch ( Exception ex )
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
}
}
 
G

Guest

jm,

How did you compile the code behind pages? Also you may wish to include AutoEventWireUp="false" attribute into your
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="CSharpUpload.WebForm1" %

Cheers
Jonathan Ruckert
 
J

jm

I know I'm gonna get thrashed for this, but you wouldn't mind giving
me a link or something tell me how to do that. I have only written
the code all in the same web page. Have mercy. Thank you.
 
J

jm

I changed Codebehind= to src=.

I know I'm gonna get thrashed for this, but you wouldn't mind giving
me a link or something tell me how to do that. I have only written
the code all in the same web page. Have mercy. Thank you.
 

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

Top