首页 > 代码库 > 上传多张图片用Session临时存储

上传多张图片用Session临时存储

  DataTable dtImages = new DataTable();            string filepath = FileUpload1.PostedFile.FileName;            //检查是否有文件要上传              if (this.FileUpload1.HasFile)            {                if (this.FileUpload1.PostedFile.ContentLength > 3096000)                {                    webmsg.message("文件不能超过3M!");                    return;                }                filepath = FileUpload1.FileName;                string filetype = System.IO.Path.GetExtension(filepath).ToLower();//获得后缀名                  if (filetype == ".jpg" || filetype == ".png" || filetype == ".gif")                {                    DateTime dt = DateTime.Now;                    string filename = string.Format("{0:yyyyMMddHHmmssffff}", dt) + filetype;                    string savepath = Server.MapPath("../StudentCenter/Upload/") + filename;                    FileUpload1.PostedFile.SaveAs(savepath);                    string imgurl = "../StudentCenter/Upload/" + filename;                    if (Session["UPLOAD"] == null)                    {                        dtImages.Columns.Add("imgUrl", typeof(object));                        dtImages.Rows.Add(new object[] { imgurl });                        Session["UPLOAD"] = dtImages;                    }                    else                    {                        dtImages = Session["UPLOAD"] as DataTable;                        dtImages.Rows.Add(new object[] { imgurl });                        Session["UPLOAD"] = dtImages;                    }                    dlst_img.DataSource = Session["UPLOAD"];                    dlst_img.DataBind();                }                else                {                    webmsg.message("请上传jpg或png或gif的图片格式!");                }            }

 

上传多张图片用Session临时存储