if (FileUpload1.HasFile)
{}
else
{
    error
}

解决方案 »

  1.   

     //多附件上传
                    for (int i = 0; i < fc.Count; i++)
                    {
                        if (fc[i].FileName != "")
                        {
                            string filePhysicalPath = "";
                            try
                            {
                                HttpPostedFile hPostedFile = fc[i];
                                int Filelong = hPostedFile.ContentLength;
                                if (Filelong > Convert.ToInt32(ConfigurationManager.AppSettings["FileZize"].ToString()))
                                {
                                    Response.Write("<script>alert('" + "文件过大,上传失败!" + "');</script>");
                                    return;
                                }
                                string RandomString = Convert.ToString(Guid.NewGuid());
                                string TrueName = Path.GetFileName(fc[i].FileName);
                                string ExtendName = TrueName.Substring(TrueName.LastIndexOf("."));
                                string RandomName = RandomString + ExtendName;
                                filePhysicalPath = Server.MapPath("~/UpLoad/DepartmentWork/" + RandomName);
                                if (!Directory.Exists(filePhysicalPath))
                                {
                                    Directory.CreateDirectory(Server.MapPath("~/UpLoad/DepartmentWork/"));
                                }
                                fc[i].SaveAs(filePhysicalPath);                            db.AddAttach(RandomName, AddID, TrueName);
                                log.AddLog("添加", "", "信息标题为:《" + txtname.Text + "》的《" + TrueName + "》附件");
                            }
                            catch
                            {
                                Response.Write("<script language=javascript>alert('上传文件出错!');</script>");
                            }
                        }
                    }