温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:逐迹内容管理系统AspxNuke v2.0源码
当前文件:
AspxNuke/Common/Library/Web/UploadHelper.cs[2K,2009-6-12 11:32:25],打开代码结构图
AspxNuke/Common/Library/Web/UploadHelper.cs[2K,2009-6-12 11:32:25],打开代码结构图1using System; 2
using System.IO; 3
using System.Web; 4
using System.Web.UI.WebControls; 5
using AspxNuke.Library.Globalization; 6
7
namespace AspxNuke.Library.Web 8
{ 9
/// <summary> 10
/// 上传帮助类 11
/// </summary> 12
public class UploadHelper 13
{ 14
private string _filePath = ConfigHelper.FilePath; 15
private int _fileSize = ConfigHelper.FileSize; 16
17
private string _message = string.Empty; 18
19
/// <summary> 20
/// 反馈消息 21
/// </summary> 22
public string Message 23
{ 24
set { _message = value; } 25
get { return _message; } 26
} 27
28
/// <summary> 29
/// 上传文件 30
/// </summary> 31
/// <param name="fileUpload">上传控件</param> 32
/// <param name="upPath">上传目录</param> 33
public void SaveAs(FileUpload fileUpload, out string upPath) 34
{ 35
if (fileUpload == null) 36
{ 37
throw new ArgumentNullException("fileUpload"); 38
} 39
40
upPath = string.Empty; 41
42
try 43
{ 44
int size = fileUpload.PostedFile.ContentLength; 45
46
//判断文件大小 47
if (size > _fileSize) 48
{ 49
_message = "文件太大,不能上传!"; 50
} 51
else 52
{ 53
upPath = _filePath + DateTime.Now.ToShortDateString(); 54
//判断目录是否存在,不存在创建目录 55
if (!Directory.Exists(HttpContext.Current.Server.MapPath(upPath))) 56
{ 57
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(upPath)); 58
} 59
string filename = string.Concat(upPath, @"/", fileUpload.FileName); 60
61
upPath = filename; 62
63
//上传文件 64
fileUpload.SaveAs(HttpContext.Current.Server.MapPath(filename)); 65
} 66
} 67
catch (Exception ex) 68
{ 69
_message = "文件上传失败:" + ex.Message; 70
throw; 71
} 72
} 73
} 74
}






}