欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

收藏的asp.net文件上傳類源碼

 更新時間:2007年03月12日 00:00:00   作者:  
namespace Wmj 

public class MyUpload 

private System.Web.HttpPostedFile postedFile=null; 
private string savePath=""; 
private string extension=""; 
private int fileLength=0; 
//顯示該組件使用的參數(shù)信息 
public string Help 

get{ 
string helpstring; 
helpstring="<font size=3>MyUpload myUpload=new MyUpload(); //構(gòu)造函數(shù)"; 
helpstring+="myUpload.PostedFile=file1.PostedFile;//設(shè)置要上傳的文件"; 
helpstring+="myUpload.SavePath=\"e:\\\";//設(shè)置要上傳到服務(wù)器的路徑,默認(rèn)c:\\"; 
helpstring+="myUpload.FileLength=100; //設(shè)置上傳文件的最大長度,單位k,默認(rèn)1k"; 
helpstring+="myUpload.Extension=\"doc\";設(shè)置上傳文件的擴(kuò)展名,默認(rèn)txt"; 
helpstring+="label1.Text=myUpload.Upload();//開始上傳,并顯示上傳結(jié)果</font>"; 
helpstring+="<font size=3 color=red>Design By WengMingJun 2001-12-12 All Right Reserved!</font>"; 
return helpstring; 


public System.Web.HttpPostedFile PostedFile 

get 

return postedFile; 

set 

postedFile=value; 


public string SavePath 

get 

if(savePath!="") return savePath; 
return "c:\\"; 

set 

savePath=value; 


public int FileLength 

get 

if(fileLength!=0) return fileLength; 
return 1024; 

set 

fileLength=value*1024; 


public string Extension 

get 

if(extension!="") return extension; 
return "txt"; 

set 

extension=value; 


public string PathToName(string path) 

int pos=path.LastIndexOf("\\"); 
return path.Substring(pos+1); 

public string Upload() 

if(PostedFile!=null) 

try{ 
string fileName=PathToName(PostedFile.FileName); 
if(!fileName.EndsWith(Extension)) return "You must select "+Extension+" file!"; 
if(PostedFile.ContentLength>FileLength) return "File too big!"; 
PostedFile.SaveAs(SavePath+fileName); 
return "Upload File Successfully!"; 

catch(System.Exception exc) 
{return exc.Message;} 

return "Please select a file to upload!"; 



用csc /target:Library Wmj.cs 編譯成dll供以后多次調(diào)用 
調(diào)用舉例 
<%@page language="C#" runat="server"%> 
<%@import namespace="Wmj"%> 
<script language="C#" runat="server"> 
void Upload(object sender,EventArgs e) 

MyUpload myUpload=new MyUpload(); 
// label1.Text=myUpload.Help; 
myUpload.PostedFile=file1.PostedFile; 
myUpload.SavePath="e:\\"; 
myUpload.FileLength=100; 
label1.Text=myUpload.Upload(); 

</script> 
<form enctype="multipart/form-data" runat="server"> 
<input type="file" id="file1" runat="server"/> 
<asp:Button id="button1" Text="Upload" OnClick="Upload" runat="server"/> 
<asp:Label id="label1" runat="server"/> 
</form> 

相關(guān)文章

  • asp.net FindControl方法誤區(qū)和解析

    asp.net FindControl方法誤區(qū)和解析

    在ASP.NET中Control都有一個FindControl方法,其作用是根據(jù)ID(注意既不是UniqueID也不是ClientID)在Control所在的命名容器中尋找相應(yīng)控件,但實(shí)際使用中存在很多誤區(qū)和陷阱,下面談?wù)剛€人對此的理解
    2012-01-01
  • .Net創(chuàng)建型設(shè)計模式之原型模式(Prototype)

    .Net創(chuàng)建型設(shè)計模式之原型模式(Prototype)

    這篇文章介紹了.Net設(shè)計模式之原型模式(Prototype),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • asp.net平臺下C#實(shí)現(xiàn)Socket通信

    asp.net平臺下C#實(shí)現(xiàn)Socket通信

    這篇文章介紹了asp.net平臺下C#實(shí)現(xiàn)Socket通信的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • .Net行為型設(shè)計模式之備忘錄模式(Memento)

    .Net行為型設(shè)計模式之備忘錄模式(Memento)

    這篇文章介紹了.Net行為型設(shè)計模式之備忘錄模式(Memento),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • SqlConnection.ConnectionString相關(guān)關(guān)鍵字

    SqlConnection.ConnectionString相關(guān)關(guān)鍵字

    SqlConnection.ConnectionString相關(guān)關(guān)鍵字...
    2007-01-01
  • ASP.NET MVC中兩個配置文件的作用詳解

    ASP.NET MVC中兩個配置文件的作用詳解

    本文詳細(xì)講解了ASP.NET MVC中兩個配置文件的作用,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • .Net行為型設(shè)計模式之解釋器模式(Interpreter)

    .Net行為型設(shè)計模式之解釋器模式(Interpreter)

    這篇文章介紹了.Net行為型設(shè)計模式之解釋器模式(Interpreter),文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • ASP.NET 入門的五個步驟

    ASP.NET 入門的五個步驟

    ASP.NET 入門的五個步驟...
    2007-01-01
  • .NET?Core使用CZGL.SystemInfo庫獲取主機(jī)運(yùn)行資源

    .NET?Core使用CZGL.SystemInfo庫獲取主機(jī)運(yùn)行資源

    這篇文章介紹了.NET?Core使用CZGL.SystemInfo庫獲取主機(jī)運(yùn)行資源的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • WPF框架Prism中ViewModelLocator用法介紹

    WPF框架Prism中ViewModelLocator用法介紹

    這篇文章介紹了WPF框架Prism中ViewModelLocator的用法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-02-02

最新評論