UploadImage.aspx的代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadImage.aspx.cs" Inherits="UploadImage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
上传图片(选择你要上传的图片)
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<P> 文件说明(添加图片说明.如:作者,说明,出处)
<asp:TextBox ID="TextBox1" runat="server" Height="24px"></asp:TextBox>
</p>
<p>
<asp:Label ID="Label1" runat="server" Text="txtMessage"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
Width="190px" />
</p>
</form>
</body>
</html>
UploadImage.aspx.cs的代码如下:
using System;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class UploadImage : Page
{
protected HtmlInputFile UP_FILE; //HtmlControl、WebControls控件对象
protected TextBox txtDescription;
protected Label txtMessage;
protected Int32 FileLength = 0; //记录文件长度变量
protected void Button_Submit(System.Object sender, System.EventArgs e)
{
HttpPostedFile UpFile = UP_FILE.PostedFile; //HttpPostedFile对象,用于读取图象文件属性
FileLength = UpFile.ContentLength; //记录文件长度
try
{
if (FileLength == 0)