栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

收藏的asp.net文件上传类源码

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

收藏的asp.net文件上传类源码

namespace Wmj 

public class MyUpload 

private System.Web.HttpPostedFile postedFile=null; 
private string savePath=""; 
private string extension=""; 
private int fileLength=0; 
//显示该组件使用的参数信息 
public string Help 

get{ 
string helpstring; 
helpstring="MyUpload myUpload=new MyUpload(); //构造函数"; 
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();//开始上传,并显示上传结果"; 
helpstring+="Design By WengMingJun 2001-12-12 All Right Reserved!"; 
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供以后多次调用 
调用举例 
<%@page language="C#" runat="server"%> 
<%@import namespace="Wmj"%> 
 
 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/59808.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号