Due to circumstances my coding environment must change to VS 2008. Now, I am usually accustomed to more linux friendly platforms, which VS is most certainly not. Since I'm simply trying to get a firm grasp of ASP 3.5, I've decided to try and build a few controls. So I what I did was created a simple webpage using the built in FileUpload control, a Button, and a Label. I'm not new to HTML either, so It was fairly painless to get that code to function, and I did confirm a file ended up on my server where I told it to go. So now I'm trying to dive into what ASP seems to be all about, modularizing via controls! So here's the deal, all my code compiles, displays correctly...etc....but when I click the button to upload, I get a "Page Cannot be Displayed" error, and the file does not upload! Any Ideas? I'm pasting the code here.
Edit: It's worth noting that I'm using IE 6.0, and am using the "View in Browser" feature to test this in VS 2008. Thanks!Default.aspx:
<%@ Register TagPrefix="UC1" TagName="UploadBox" src="UploadControl.ascx"%><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MC_FAS._Default" %><!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 runat="server"> <title>Test Page</title></head><body> <form id="form1" runat="server"> <UC1:UploadBox runat="server" ID="wawfsbox"/> </form></body></html>
UploadControl.ascx:<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="UploadControl.ascx.cs" Inherits="UploadControl.UploadControlClass"%><asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button ID="Button1" runat="server" Text="Upload"/><asp:Label ID="Label1" runat="server"></asp:Label>
UploadControl.ascx.cs:namespace UploadControl{using System;
using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;public abstract class UploadControlClass : System.Web.UI.UserControl{
protected System.Web.UI.WebControls.FileUpload FileUpload1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; private void Button1_Click(object sender, EventArgs e) { Response.Write("Clicked"); if (FileUpload1.HasFile) try { FileUpload1.SaveAs("D:\\~Path~\\" + FileUpload1.FileName); //Path to place file Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "<br>" + FileUpload1.PostedFile.ContentLength + " kb<br>" + "Content type: " + FileUpload1.PostedFile.ContentType; } catch (Exception ex) { Label1.Text = "ERROR: " + ex.Message.ToString(); } else { Label1.Text = "You have not specified a file."; } } //End of Button1_Click Event************************************
}}
Now, keep in mind, I dont get any parser errors, just a page cannot be displayed!