62,046
社区成员
发帖
与我相关
我的任务
分享
private void FN_UpFiles()
{
//遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
//检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName = "";
fileName = Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
try
{
string strpath = System.Web.HttpContext.Current.Request.MapPath("~/ResourcesFolder/") + fileName;
if (System.IO.File.Exists(strpath))
{
Response.Write("已经存在文件:" + fileName + "<br>");
}
else
{
try
{
NRModel.File model = new NRModel.File();
NRBLL.File bf = new NRBLL.File();
Guid guid1 = Guid.NewGuid();
Guid guid2 = Guid.NewGuid();
Guid guid3 = Guid.NewGuid();
Guid guid4 = Guid.NewGuid();
model.Fileid = guid1;
model.Folderid = guid2;
model.Filepath = strpath;
model.FileNam = fileName.ToString();
model.FileSize = postedFile.ContentLength;
model.Decription = this.decrition.Value;
model.CreateOn = DateTime.Now;
model.CreateBy = guid3;
model.ModefyBy = guid4;
if (bf.FN_AddNewRes(model) > 0)
{
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/ResourcesFolder/") + fileName);
Page.RegisterStartupScript("提示", "<script language='javascript'>alert('上传成功!')</script>");
//Response.Write("<script language='javascript'>window.close();</script>");
//Response.Write("<script language='javascript'>self.opener.location.reload();</script>");
}
else
{
Page.RegisterStartupScript("提示", "<script language='javascript'>alert('上传失败!')</script>");
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
}
catch (System.Exception ex)
{
Response.Write(ex.ToString());
}
}