错误:无法加载类型'upload.aspx'。 [英] Error: Could not load type 'upload.aspx'.

查看:72
本文介绍了错误:无法加载类型'upload.aspx'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试创建一个网页来上传图片。我将复制下面的代码



---------------------------- -------------------------------------------------- -

Hi,

I am trying to create a web page to upload an image. I will copy the code below

-------------------------------------------------------------------------------

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 netimageupload
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlInputFile filUpload;
		protected System.Web.UI.WebControls.Image imgPicture;
		protected System.Web.UI.WebControls.Label lblOutput;
		protected System.Web.UI.WebControls.Button btnUpload;
	
		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.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnUpload_Click(object sender, System.EventArgs e)
		{
			// Initialize variables
			string sSavePath;
			string sThumbExtension;
			int intThumbWidth;
			int intThumbHeight;

			// Set constant values
			sSavePath = "images/";
			sThumbExtension = "_thumb";
			intThumbWidth = 160;
			intThumbHeight = 120;

			// If file field isn’t empty
			if (filUpload.PostedFile != null)
			{
				// Check file size (mustn’t be 0)
				HttpPostedFile myFile = filUpload.PostedFile;
				int nFileLen = myFile.ContentLength;
				if (nFileLen == 0)
				{
					lblOutput.Text = "There wasn't any file uploaded.";
					return;
				}

				// Check file extension (must be JPG)
				if (System.IO.Path.GetExtension(myFile.FileName).ToLower() != ".jpg")
				{
					lblOutput.Text = "The file must have an extension of JPG";
					return;
				}

				// Read file into a data stream
				byte[] myData = new Byte[nFileLen];
				myFile.InputStream.Read(myData,0,nFileLen);

				// Make sure a duplicate file doesn’t exist.  If it does, keep on appending an incremental numeric until it is unique
				string sFilename = System.IO.Path.GetFileName(myFile.FileName);
				int file_append = 0;
				while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
				{
					file_append++;
					sFilename = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + ".jpg";
				}

				// Save the stream to disk
				System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename), System.IO.FileMode.Create);
				newFile.Write(myData,0, myData.Length);
				newFile.Close();

				// Check whether the file is really a JPEG by opening it
				System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
				Bitmap myBitmap;
				try
				{
					myBitmap = new Bitmap(Server.MapPath(sSavePath + sFilename));

					// If jpg file is a jpeg, create a thumbnail filename that is unique.
					file_append = 0;
					string sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + sThumbExtension + ".jpg";
					while (System.IO.File.Exists(Server.MapPath(sSavePath + sThumbFile)))
					{
						file_append++;
						sThumbFile = System.IO.Path.GetFileNameWithoutExtension(myFile.FileName) + file_append.ToString() + sThumbExtension + ".jpg";
					}

					// Save thumbnail and output it onto the webpage
					System.Drawing.Image myThumbnail = myBitmap.GetThumbnailImage(intThumbWidth, intThumbHeight, myCallBack, IntPtr.Zero);
					myThumbnail.Save (Server.MapPath(sSavePath + sThumbFile));
					imgPicture.ImageUrl = sSavePath + sThumbFile;

					// Displaying success information
					lblOutput.Text = "File uploaded successfully!";

					// Destroy objects
					myThumbnail.Dispose();
					myBitmap.Dispose();
				}
				catch (ArgumentException errArgument)
				{
					// The file wasn't a valid jpg file
					lblOutput.Text = "The file wasn't a valid jpg file.";
					System.IO.File.Delete(Server.MapPath(sSavePath + sFilename));
				}
			}
		}

		public bool ThumbnailCallback()
		{
			return false;
		}
	}
}



-------------------- -------------------------------------------------- -------------

在构建网站时,我收到错误消息无法加载类型upload.aspx>

我从Code Project获得此代码。



请帮助.....



代码块添加 - OriginalGriff [/ edit]


-----------------------------------------------------------------------------------
While building the web site i am getting an error messae "Could not load type upload.aspx>
I got this code from Code Project.

Please help.....

[edit]Code block added - OriginalGriff[/edit]

推荐答案

不要在快速答案下发布 - 如果你从文章中得到了代码,那么就有一个新的消息该文章底部的按钮,它会将一封电子邮件发送给作者。然后他们会收到通知您希望与他们交谈。

在此处发布此消息依赖于他们 并意识到这是为了他们。
Don''t post this under Quick Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.


这篇关于错误:无法加载类型'upload.aspx'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆