1、Upfile.aspx:
2、Upfile.aspx.cs
3、类文件:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Upfile.aspx.cs
"
Inherits
=
"
Inc_Upfile
"
%>
<! 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 > 上传文件 </ title >
< link href = " ../Manage/Style.Css " type = " text/css " rel = Stylesheet />
</ head >
< body >
< form id = " form1 " runat = " server " >
< div style = " left: 0px; clip: rect(0px auto auto 0px); position: absolute; top: 0px " >
< asp:FileUpload ID = " FileUpload1 " runat = " server " />
< asp:Button ID = " Button1 " runat = " server " OnClick = " Button1_Click " Text = " 上传文件 " CssClass = " btn2 " />
< asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label ></ div >
</ form >
</ body >
</ html >
<! 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 > 上传文件 </ title >
< link href = " ../Manage/Style.Css " type = " text/css " rel = Stylesheet />
</ head >
< body >
< form id = " form1 " runat = " server " >
< div style = " left: 0px; clip: rect(0px auto auto 0px); position: absolute; top: 0px " >
< asp:FileUpload ID = " FileUpload1 " runat = " server " />
< asp:Button ID = " Button1 " runat = " server " OnClick = " Button1_Click " Text = " 上传文件 " CssClass = " btn2 " />
< asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label ></ div >
</ form >
</ body >
</ html >
2、Upfile.aspx.cs
using
System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Inc_Upfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Cut By 梦溪苑。
}
protected void Button1_Click(object sender, EventArgs e)
{
AllSheng.upload UpFiles = new AllSheng.upload();
//HttpPostedFile File = FileUpload1.PostedFile;
// AllSheng.UploadObj.PhotoSave("/", FileUpload1);
HttpFileCollection files = HttpContext.Current.Request.Files;
UpFiles.Path = "../UpLoadfiles";
String ReStr= UpFiles.SaveAs(files).ToString();
Label1.Text = ReStr;
UpFiles = null;
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Inc_Upfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Cut By 梦溪苑。
}
protected void Button1_Click(object sender, EventArgs e)
{
AllSheng.upload UpFiles = new AllSheng.upload();
//HttpPostedFile File = FileUpload1.PostedFile;
// AllSheng.UploadObj.PhotoSave("/", FileUpload1);
HttpFileCollection files = HttpContext.Current.Request.Files;
UpFiles.Path = "../UpLoadfiles";
String ReStr= UpFiles.SaveAs(files).ToString();
Label1.Text = ReStr;
UpFiles = null;
}
}
3、类文件:
using
System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Cls_Upfile 的摘要说明
/// </summary>
///
namespace AllSheng
{
public class upload
{
变量
upload():初始化变量
设置传入的值:Path/Sizes/FileType
SaveAs()上传文件
getSaveFileFolderPath(...):获得保存的文件夹的物理路径
getFileExtension(...):获取原文件的扩展名
message(...):弹出消息框
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Cls_Upfile 的摘要说明
/// </summary>
///
namespace AllSheng
{
public class upload
{
变量
upload():初始化变量
设置传入的值:Path/Sizes/FileType
SaveAs()上传文件
getSaveFileFolderPath(...):获得保存的文件夹的物理路径
getFileExtension(...):获取原文件的扩展名
message(...):弹出消息框
}
}