分用户文件夹上传图片

来源:互联网 发布:tomcat数据库密码 编辑:程序博客网 时间:2024/05/02 01:30

  //分客户分类别建立上传图片的文件夹
            if (!Directory.Exists(HttpContext.Current.Server.MapPath("uploadfile/") + "//" + CurrentLoginUser.LoginName+"//产品图片"))
            {
                Directory.CreateDirectory(@HttpContext.Current.Server.MapPath("uploadfile/") + "//" + CurrentLoginUser.LoginName+"//产品图片");
            }
            if (FileUpload1.PostedFile.FileName != "")
            {
                string ImgPath = FileUpload1.PostedFile.FileName;
                string ImgName = ImgPath.Substring(ImgPath.LastIndexOf("//") + 1);
                string ImgExtend = ImgPath.Substring(ImgPath.LastIndexOf(".") + 1);
                if (!(ImgExtend == "bmp" || ImgExtend == "jpg" || ImgExtend == "gif"))
                {
                    return;
                }
                string ServerPath = Server.MapPath("uploadfile/"+CurrentLoginUser.LoginName+"/产品图片/") + ImgName;
                FileUpload1.PostedFile.SaveAs(ServerPath);
                ProModel.photoFile = ImgName;
            }

            productHelper insertPro = new productHelper();
            insertPro.product = ProModel;