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());
}
}
这是我一段上传文件的函数.
当我的文件上传完毕 当前页面关闭 刷新父页面 可是总是有时刷新 有时不刷新 有什么办法可以必刷呢?
Response.Write("<script language='javascript'>self.opener.location.reload();</script>");调换一位置看看。
Response.Write("<script language='javascript'>self.opener.location.reload();</script>");
Response.Write("<script language='javascript'>window.close();</script>");