📄 addenhanced.ascx.cs
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace MySite.WebUI.Controls.FileUpload
{
using SubSonic.Generated;
using SubSonic;
using MySite.Utils;
public partial class AddEnhanced : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if(this.IsPostBack)
_SaveUpload();
}
private bool _SaveUpload()
{
int filenum = Convert.ToInt32(this.Request["filenum"]);
/// '状态信息
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("上传的文件分别是:<hr color=green>");
try
{
for(int i=1;i<=filenum;i++)
{
bool isSuccess = true;
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
///'检查文件扩展名字
HttpPostedFile postedFile = this.Request.Files["file"+i.ToString()];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("文件" + i.ToString()+" ");
strMsg.Append("客户端文件地址:" + postedFile.FileName + " ");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
//判断是否已存在同名文件
if(!string.IsNullOrEmpty(this.Request["txtFileName"+i.ToString()]))
fileName=this.Request["txtFileName"+i.ToString()];
strMsg.Append("欲上传文件的文件名:" + fileName + " ");
if (System.IO.File.Exists(this.Request.MapPath(ConfigurationManager.AppSettings["Path"]+"Upload/") + fileName))
{
if (string.IsNullOrEmpty(this.Request["chkbxIsOverride" + i.ToString()]))
{
isSuccess = false;
strMsg.Append("上传失败,由于存在已存在同名文件,并未勾选覆盖选项");
}
else
{
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(ConfigurationManager.AppSettings["Path"] + "Upload/") + fileName);
}
}
else {
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(ConfigurationManager.AppSettings["Path"] + "Upload/") + fileName);
strMsg.Append("上传成功");
TagCollection tagColl=Tag.UpdateAndReturnTags(this.Request["txtTag"+i.ToString()]);
FileLog fl = new FileLog();
fl.FileUrl = "Upload/" + fileName;
fl.Description = this.Request["txtDesciption" + i.ToString()];
fl.Username = HttpContext.Current.User.Identity.Name;
fl.Save();
FileLog.SaveTagMap(fl.PKId, tagColl);
}
if (isSuccess)
{
sb.AppendFormat(@"<FONT SIZE=""3"" COLOR=""blue"">{0}</FONT><br>",strMsg.ToString());
}
else
{
sb.AppendFormat(@"<FONT SIZE=""3"" COLOR=""red"">{0}</FONT><br>",strMsg.ToString());
}
}
}
strStatus.Text = sb.ToString();
return true;
}
catch (System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -