上传文件

//建立保存上传文件的文件夹

if(!IsPostBack)
{
#region [文件上传]
UpLoadHelper uh = new UpLoadHelper();
uh.RegisterProgressBar();
string path = Path.Combine(Request.PhysicalApplicationPath,Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["LawerFilePath"]));
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
uh.UploadFolder=path;
#endregion

}

//执行上传命令

private void bttnSubmit_Click(object sender, System.EventArgs e)
{
#region [上传文件]
string path = "";
//文件原名
string _OldFileName = "";
//string strName = "";
//string strLastName = "";
UpLoadHelper uh = new UpLoadHelper();
foreach(UpLoadFile file in uh.GetUploadFileList("file"))
{
//文件类型
string strExtention = Path.GetExtension(file.FileName).ToLower();
//文件名
string strFileName = Path.GetFileName(file.FileName).ToLower();
//文件原名
_OldFileName = strFileName.Substring(0,strFileName.Length - strExtention.Length);
//图片
path = Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["LawerFilePath"].ToString());


//文件名称
//strName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fffffff");
//if(strName.Equals(strLastName.TrimEnd('_')))
//{
//strName = strLastName + "_";
//}
//strLastName = strName;
//strName += strExtention;
_OldFileName += strExtention;
file.SaveAs(Path.Combine(path,_OldFileName));

}
#endregion

}

你可能感兴趣的:(上传文件)