富贵资源网 Design By www.hznty.com
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="<font size=3>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();//开始上传,并显示上传结果</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供以后多次调用
调用举例
<%@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>
{
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="<font size=3>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();//开始上传,并显示上传结果</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供以后多次调用
调用举例
<%@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>
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?