色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

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(); //構造函數(shù)"; 
helpstring+="myUpload.PostedFile=file1.PostedFile;//設置要上傳的文件"; 
helpstring+="myUpload.SavePath=/"e:///";//設置要上傳到服務器的路徑,默認c://"; 
helpstring+="myUpload.FileLength=100; //設置上傳文件的最大長度,單位k,默認1k"; 
helpstring+="myUpload.Extension=/"doc/";設置上傳文件的擴展名,默認txt"; 
helpstring+="label1.Text=myUpload.Upload();//開始上傳,并顯示上傳結果</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("http://"); 
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供以后多次調用 
調用舉例 
<%@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> 

AspNet技術收藏的asp.net文件上傳類源碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 三明市| 泗水县| 贵南县| 屏东县| 临沂市| 筠连县| 郎溪县| 虞城县| 达尔| 尚义县| 紫云| 中超| 徐水县| 大兴区| 都兰县| 邛崃市| 永泰县| 榆社县| 曲阜市| 浙江省| 右玉县| 蓝山县| 朔州市| 资中县| 墨玉县| 灵璧县| 铜川市| 盐池县| 怀宁县| 厦门市| 始兴县| 郓城县| 桃江县| 民乐县| 景东| 山阳县| 资阳市| 石嘴山市| 金山区| 巴塘县| 句容市|