All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0中发送电子邮件剖析之一_.net资料_编程技术
新手学习PHP的一些基础知识_[PHP教程]
用javascript操纵GridView中CheckBox的两个常用技巧_[Asp.Net教程]
PHP结合MySQL初级网站编程教程_[PHP教程]
ASP.Net中FileUpLoad控件内容清空
关于PHP动态网页session问题的解决方案_[PHP教程]
ASP.NET,2.0中GridView无限层复杂表头的实现_[Asp.Net教程]
多种方法实现超长字符用-.....-代替_[Asp.Net教程]
oracle,SQL性能优化_mssql学习_编程技术
开发ASP.NET,Atlas服务器端Extender控件—编写服务器端Extender,&,Dfl_[Asp.Net教程]
Reading number is top 10 pictures
心有鱼而力不足
谁认识这位校花
Sora aoi on twitter5
Sell the barbecue as says father du breul1
生活中总有些低调的人,不经意间散发出土豪的气质
2012 national geographic daily picture1
非常漂亮的泳装美女
The money of more than 100 countries and regions22
关于海盗的研究
Exquisite decoration is not paying too much3
Download software ranking
WebService在.NET中的实战应用教学视频 → 第5集
Tram sex maniac 2 (H) rar bag19
Wild things 2
Tram sex maniac 2 (H) rar bag18
致我们终将逝去的青春
变速齿轮3.26
Twenty piece of palm leaf
徐若瑄成名作“魔鬼天使”
WebService在.NET中的实战应用教学视频 → 第3集
C语言教程TXT
delv published in(发表于) 2014/1/24 9:02:51 Edit(编辑)
ASP.NET,中的上传控件使用_[Asp.Net教程]

ASP.NET,中的上传控件使用_[Asp.Net教程]

ASP.NET 中的上传控件使用_[Asp.Net教程]

using System;
using System.Data;
using System.Configuration;
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;

///
/// MyUpload 的摘要说明
///

public class MyUpload
{
private System.Web.HttpPostedFile postedFile = null;
private string savePath = "";
private string[] extension;
private int fileLength = 0;
public string[] filestype ={ "txt", "doc", "gif" };
public MyUpload()
{
//
// TOD 在此处添加构造函数逻辑
//
}
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 += "";
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 = HttpContext.Current.Server.MapPath("../upimages/") + value;/////////////////////注意这里选取上传文件路径,可以修改成传递参数类型的
}
}

public int FileLength
{
get
{
if (fileLength != 0) return fileLength;
return 1024;
}
set
{
fileLength = value * 1024;
}
}

public string[] Extension
{
get
{
if (extension != null) return extension;
return filestype;
}
set
{
extension = value;
}
}

public string PathToName(string path)
{
int pos = path.LastIndexOf("\\");
return path.Substring(pos + 1);
}

public string Upload()
{
int biaoshi = 0;
if (PostedFile.FileName != "")
{
try
{
string fileName = PathToName(PostedFile.FileName);
for (int i = 0; i < Extension.Length; i++)
{
if (fileName.EndsWith(Extension[i]))
{
biaoshi = 1;
}
}
if (biaoshi != 1)
{
string errs = "";
for (int i = 0; i < Extension.Length; i++)
{
errs = errs + Extension[i] + "/";
}
return "您必须选择" + errs + "类型的文件!";
}
if (PostedFile.ContentLength > FileLength) return "文件太大,超过了限定值!";
PostedFile.SaveAs(SavePath + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + fileName.Substring(fileName.Length - 4, 4));
return DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + fileName.Substring(fileName.Length - 4, 4);
}
catch (System.Exception exc) { return exc.Message; }
}
return "请选择文件后再进行上传!";
}
}

////////////////////使用例子,直接复制没有修改/////////////////////
string[] filestype ={ "gif", "jpg", "png" };
MyUpload myload = new MyUpload();
myload.PostedFile = File1.PostedFile;
myload.SavePath = "";
myload.FileLength = 1000;
myload.Extension = filestype;
Label1.Text = myload.Upload();
if (Label1.Text.StartsWith("200"))
{
Label2.Text = "upimages/" + Label1.Text;

Label1.Text = "上传更新成功!";
}

来源:CSDN






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.