Exemplo n.º 1
0
        public static BizResultInfo UploadFileToUserImportFile(HttpRequestBase requestBase)
        {
            BizResultInfo result = new BizResultInfo();

            if (requestBase.Files.Count == 0)
            {
                result.IsSuccess    = false;
                result.ErrorMessage = "没有文件呀,选择文件之后再上传啊。";
                return(result);
            }
            var file = requestBase.Files[0];

            if (file.ContentType.ToLower() != "text/html" && file.ContentType.ToLower() != "text/htm")
            {
                result.IsSuccess    = false;
                result.ErrorMessage = "文件格式不正确,请上传后缀为HTML/HTM的书签文件。";
                return(result);
            }

            string path     = AppDomain.CurrentDomain.BaseDirectory + "UploadFiles/UserImportFile/";
            string filename = Path.GetFileName(file.FileName);
            Random ran      = new Random();
            int    randKey  = ran.Next(0, 99999);

            filename = DateTime.Now.ToString("yyyyMMdd") + randKey + filename;
            file.SaveAs(Path.Combine(path, filename));
            result.IsSuccess = true;

            //BizUserWebBookmarkImportLog importLog = new BizUserWebBookmarkImportLog();
            //importLog.FileName = filename;
            //importLog.Path = "~/UploadFiles/UserImportFile/" + filename;
            //importLog.CreateTime = DateTime.Now;
            //result.Target = importLog;
            return(result);
        }
Exemplo n.º 2
0
        public static BizResultInfo UploadFileToUserImg(HttpRequestBase requestBase)
        {
            BizResultInfo result = new BizResultInfo();

            if (requestBase.Files.Count == 0)
            {
                result.IsSuccess    = false;
                result.ErrorMessage = "没有文件呀,选择文件之后再上传啊。";
                return(result);
            }
            var file = requestBase.Files[0];

            string path     = AppDomain.CurrentDomain.BaseDirectory + "UploadFiles/UserImg/";
            string filename = Path.GetFileName(file.FileName);
            Random ran      = new Random();
            int    randKey  = ran.Next(0, 99999);

            filename = DateTime.Now.ToString("yyyyMMdd") + randKey + filename;
            file.SaveAs(Path.Combine(path, filename));

            if (!IsIMGAllowedExtension(file.InputStream))
            {
                result.IsSuccess    = false;
                result.ErrorMessage = "啦啦啦,文件类型不合法,你娃是来整木马的?";

                if (System.IO.File.Exists(path + filename))
                {
                    System.IO.File.Delete(path + filename);
                }
                return(result);
            }
            result.IsSuccess = true;
            result.ResultID  = "~/UploadFiles/UserImg/" + filename;
            return(result);
        }