Exemple #1
0
        public ActionResult AjaxFileUpload()
        {
            #region 验证用户信息
            string _SessionId       = HttpContext.Request.Cookies["SessionId"].Value;
            string _UserProfileJson = RedisHelper.ItemGet <string>(_SessionId);
            #endregion

            if (!string.IsNullOrEmpty(_UserProfileJson))
            {
                UserProfile _UserProfile = ToolMethod.GetUerProfile(_UserProfileJson);

                HttpFileCollection _Files = System.Web.HttpContext.Current.Request.Files;

                string _DateTimePath = ToolMethod.GetDateTimePath();
                string _PhysicalPath = ToolMethod.GetBlogsSurfacePlot_PhysicalPath(_DateTimePath);
                string _VirualPath   = ToolMethod.GetBlogsSurfacePlot_VirualPath(_DateTimePath);

                if (!Directory.Exists(_PhysicalPath))
                {
                    Directory.CreateDirectory(_PhysicalPath);
                }

                string _FileName         = _Files[0].FileName;
                string _StrFile          = System.DateTime.Now.ToString("yyyyMMddHHmmssms");
                string _FilePhysicalPath = _PhysicalPath + _StrFile + "_" + _FileName;
                string _FileVirualPath   = _VirualPath + _StrFile + "_" + _FileName;
                long   _FileSize         = _Files[0].ContentLength;
                //获取文件后缀
                string _FileType = _FileName.Substring(_FileName.LastIndexOf(@"."), _FileName.Length - _FileName.LastIndexOf(@"."));
                //保存文件
                _Files[0].SaveAs(_FilePhysicalPath);

                string    _FileId    = ToolMethod.GetGuid();
                ImageInfo _ImageInfo = new ImageInfo
                {
                    Id           = _FileId,
                    CDate        = ToolMethod.GetNow(),
                    Delflag      = EnumType.DelflagType.正常,
                    AccountId    = _UserProfile.Id,
                    AccountName  = _UserProfile.LoginName,
                    FileName     = _FileName,
                    FileSize     = _FileSize,
                    RelativePath = _StrFile + "_" + _FileName,
                    FileType     = _FileType
                };

                //保存文件集合
                _IImageInfoBLL.Add(_ImageInfo);

                return(Json(new { FileId = _FileId, FileName = _FileName, PhysicalPath = _FilePhysicalPath, VirualPath = _FileVirualPath }));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }