1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upfile.aspx.cs" Inherits="upfile_upfile" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>无标题页</title>
8</head>
9<body>
10 <form id="form1" runat="server">
11 <div>
12 <asp:FileUpload ID="FileUpload1" runat="server" />
13 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" /><br />
14 <asp:Label ID="Label1" runat="server"></asp:Label></div>
15 </form>
16</body>
17</html>
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11using System.IO;
12
13public partial class upfile_upfile : System.Web.UI.Page
14{
15 protected void Page_Load(object sender, EventArgs e)
16 { }
17
18 protected void Button1_Click(object sender, EventArgs e)
19 {
20 if (FileUpload1.HasFile)
21 {
22 string fileContentType = FileUpload1.PostedFile.ContentType;
23 if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/pjpeg")