Beispiel #1
0
        public IActionResult MDEditor_API()
        {
            string action = GetParam("action");
            string result = "";

            switch (action)
            {
            case "down":
            {
                string content = RequestEx["content"];
                Stream sm      = IOHelper.BytesToStream(Encoding.UTF8.GetBytes(content));
                //var memi = provider.Mappings[fileExt];
                return(File(sm, "text/plain", "content.md"));
            }

            case "upload":    //上传图片
            {
                var    file  = Request.Form.Files["editormd-image-file"];
                string vpath = ZLHelper.GetUploadDir_Anony("content", "md");
                string fname = function.GetRandomString(10) + "." + GetImgExt(file.FileName);
                string url   = SafeC.SaveFile(vpath, fname, file.OpenReadStream(), (int)file.Length);
                result = JsonHelper.GetJson(
                    new string[] { "success", "message", "url" },
                    new string[] { "1", "上传成功", url });
            }
            break;
            }
            return(Content(result));
        }
Beispiel #2
0
        public string SaveFile()
        {
            C_SFileUP model     = JsonConvert.DeserializeObject <C_SFileUP>(RequestEx["model"]);
            var       file      = Request.Form.Files["file"];
            Stream    stream    = file.OpenReadStream();
            int       conLength = (int)Request.ContentLength;
            //=================================
            string result = "";

            if (Request.ContentLength < 100 || string.IsNullOrEmpty(file.FileName))
            {
                return("");
            }
            string fname = DateTime.Now.ToString("yyyyMMddHHmm") + function.GetRandomString(4) + Path.GetExtension(file.FileName);

            switch (model.FileType)
            {
            case "img":
            {
                if (!SafeSC.IsImage(file.FileName))
                {
                    throw new Exception(Path.GetExtension(file.FileName) + "不是有效的图片格式!");
                }
                //ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                //if (model.MaxWidth > 0 || model.MaxHeight > 0)
                //{
                //    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                //    img = imghelp.ZoomImg(img, model.MaxHeight, model.MaxWidth);
                //    result = ImgHelper.SaveImage(GetSaveDir(model.SaveType) + fname, img);
                //    hasSave = true;
                //}
                if (!hasSave)
                {
                    result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                }
            }
            break;
                //case "office":
                //    {
                //        string[] exname = "doc|docx|xls|xlsx".Split('|');
                //        if (!exname.Contains(Path.GetExtension(file.FileName))) { throw new Exception("必须上传doc|docx|xls|xlsx格式的文件!"); return ""; }
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                //    }
                //    break;
                //case "all":
                //default:
                //    {
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, file.OpenReadStream(), conLength);
                //    }
                //    break;
            }
            return(result);
        }
Beispiel #3
0
 protected void Save_Btn_Click(object sender, EventArgs e)
 {
     if (NowImg_Hid.Value.Equals(SourceImg_Hid.Value))
     {
         function.WriteErrMsg("请修改后再保存");
     }
     byte[] img = SafeC.ReadFileByte(NowImg_Hid.Value);
     SafeC.SaveFile(SourceImg_Hid.Value, Path.GetFileName(SourceImg_Hid.Value), img);
     function.Script(this, "AfterSave();");
 }
Beispiel #4
0
 /// <summary>
 /// SafeSC.SaveFile(Path.GetDirectoryName(strFileName) + "\\", Path.GetFileName(strFileName), bytes);
 /// </summary>
 public static string SaveFile(string vpath, string fileName, byte[] file)
 {
     return(SafeC.SaveFile(vpath, fileName, file));
 }
Beispiel #5
0
 public static string SaveFile(string vpath, HttpPostedFile file, string fileName = "")
 {
     return(SafeC.SaveFile(vpath, file, fileName));
 }
Beispiel #6
0
 public static string SaveFile(string vpath, FileUpload file, string fileName = "")
 {
     return(SafeC.SaveFile(vpath, file, fileName));
 }
Beispiel #7
0
        public void DownPaper()
        {
            string            qids      = Request["qids"] ?? "";
            string            PaperSize = Request["PaperSize"] ?? "A4";
            bool              Orient    = string.IsNullOrEmpty(Request["Orient"]) ? true : DataConverter.CBool(Request["Orient"]);
            M_Exam_Sys_Papers paperMod  = paperBll.SelReturnModel(Mid);

            if (paperMod == null)
            {
                function.WriteErrMsg("试卷不存在");
            }
            BH.HtmlHelper htmlHelp = new BH.HtmlHelper();
            StringWriter  sw       = new StringWriter();

            Server.Execute("/BU/Exam/Paper.aspx?id=" + paperMod.id, sw, false);
            string   html = sw.ToString();
            HtmlPage page = htmlHelp.GetPage(html);

            html = page.Body.ExtractAllNodesThatMatch(new HasAttributeFilter("id", "paper"), true).ToHtml();
            string wordDir  = "/Log/Storage/Exam/Paper/";
            string wordPath = wordDir + paperMod.id + ".docx";
            string ppath    = Server.MapPath(wordPath);

            if (!Directory.Exists(Server.MapPath(wordDir)))
            {
                Directory.CreateDirectory(Server.MapPath(wordDir));
            }
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(sw.ToString()));             //convert stream 2 string

            using (MemoryStream generatedDocument = new MemoryStream())
            {
                using (WordprocessingDocument doc = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
                {
                    MainDocumentPart mainPart = doc.MainDocumentPart;
                    if (mainPart == null)
                    {
                        mainPart = doc.AddMainDocumentPart();
                        new Document(new Body()).Save(mainPart);
                    }
                    HtmlConverter converter = new HtmlConverter(mainPart);

                    //生成格式A4,A3
                    Body docBody = mainPart.Document.Body;
                    SectionProperties sectionProperties = new SectionProperties();
                    PageSize          pageSize          = new PageSize();
                    PageMargin        pageMargin        = new PageMargin();
                    //默认为16k大小
                    Columns columns = new Columns()
                    {
                        Space = "220"
                    };                                                //720
                    DocGrid docGrid = new DocGrid()
                    {
                        LinePitch = 100
                    };                                                  //360
                    GetPageSetting(ref pageSize, ref pageMargin, PaperSize, Orient);
                    sectionProperties.Append(pageSize, pageMargin, columns, docGrid);
                    docBody.Append(sectionProperties);

                    var paragraphs = converter.Parse(html);
                    for (int i = 0; i < paragraphs.Count; i++)
                    {
                        docBody.Append(paragraphs[i]);
                    }
                    mainPart.Document.Save();
                }
                SafeC.SaveFile(wordDir, paperMod.id + ".docx", generatedDocument.ToArray());
            }
            SafeSC.DownFile(wordPath, paperMod.p_name + ".docx");
        }
Beispiel #8
0
        public IActionResult UploadFileHandler()
        {
            //HttpRequest Request = context.Request;
            //context.Response.ContentType = "text/plain";
            //context.Request.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            //context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            var file = Request.Form.Files["Filedata"];

            if (file == null)
            {
                file = Request.Form.Files["file"];//接受Uploadify或WebUploader传参,优先Uploadify
            }
            if (file == null || file.Length < 1)
            {
                return(Content(Failed.ToString()));
            }
            if (SafeSC.FileNameCheck(file.FileName))
            {
                throw new Exception("不允许上传该后缀名的文件");
            }
            M_UserInfo mu = buser.GetLogin();

            if (adminMod == null && mu.IsNull)
            {
                throw new Exception("未登录");
            }
            /*-------------------------------------------------------------------------------------------*/
            M_User_Plat upMod = new B_User_Plat().SelReturnModel(mu.UserID);
            string      uploadPath = SiteConfig.SiteOption.UploadDir.TrimEnd('/') + "/", filename = "", ppath = "", result = "0";//上传根目录,文件名,上物理路径,结果
            string      action = GetParam("action"), value = GetParam("value");

            try
            {
                switch (action)
                {
                    #region OA与能力中心
                case "OAattach":    //OA--公文||事务--附件
                                    //uploadPath += "OA/" + mu.UserName + mu.UserID + "/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                    uploadPath = ZLHelper.GetUploadDir_User(mu, "OA");
                    ppath      = function.VToP(uploadPath);
                    //判断是否有同名文件的存在
                    break;

                case "Blog":    //能力中心--博客
                    uploadPath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Blog);
                    ppath      = function.VToP(uploadPath);
                    break;

                case "Plat_Doc":    //能力中心--我的文档
                    uploadPath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Person) + SafeSC.PathDeal(GetParam("Dir"));
                    ppath      = function.VToP(uploadPath);
                    break;

                case "Plat_Doc_Common":    //能力中心--公司文档
                    uploadPath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Company) + SafeSC.PathDeal(GetParam("Dir"));
                    ppath      = function.VToP(uploadPath);
                    break;

                case "Plat_Task":    //能力中心--任务中心附件
                    int tid = Convert.ToInt32(value);
                    ZoomLa.Model.Plat.M_Plat_Task taskMod = new B_Plat_Task().SelReturnModel(tid);
                    uploadPath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Plat_Task) + taskMod.TaskName + "/";
                    break;

                case "Plat_Project":    //能力中心--项目
                    int pid = Convert.ToInt32(value);
                    ZoomLa.Model.Plat.M_Plat_Pro proMod = new B_Plat_Pro().SelReturnModel(pid);
                    uploadPath = B_Plat_Common.GetDirPath(upMod, B_Plat_Common.SaveType.Plat_Task) + proMod.Name + "/";
                    break;

                    #endregion
                case "ModelFile":    //组图,多图等
                {
                    int nodeid = Convert.ToInt32(value);
                    //M_Node nodeMod = new B_Node().GetNodeXML(nodeid);
                    string exname = Path.GetExtension(file.FileName).Replace(".", "");
                    //string fpath = nodeMod.NodeDir + "/" + exname + "/" + DateTime.Now.ToString("yyyy/MM/");
                    uploadPath = ZLHelper.GetUploadDir_System("field", "images", "yyyyMMdd");
                    filename   = DateTime.Now.ToString("HHmmss") + function.GetRandomString(6, 2) + "." + exname;
                }
                break;

                case "admin_custom":    //管理员上传,自定义路径
                {
                    if (adminMod == null || adminMod.AdminId < 1)
                    {
                        throw new Exception("管理员未登录");
                    }
                    uploadPath = GetParam("save");       //BannerAdd
                }
                break;

                default:    //通常格式,不需做特殊处理的格式但必须登录
                    if (mu.UserID > 0)
                    {
                        //uploadPath = context.Server.UrlDecode(uploadPath + "User/" + mu.UserName + mu.UserID + "/");
                        uploadPath = ZLHelper.GetUploadDir_User(mu, "User", "", "");
                    }
                    else if (adminMod != null)
                    {
                        //uploadPath = context.Server.UrlDecode(uploadPath + "Admin/" + adminMod.AdminName + adminMod.AdminId + "/");
                        uploadPath = ZLHelper.GetUploadDir_Admin(adminMod, "", "", "yyyyMMdd");
                    }
                    else
                    {
                        //注册等页面用户未登录
                        uploadPath = ZLHelper.GetUploadDir_System("user", "register", DateTime.Now.ToString("yyyyMMdd"));
                    }
                    break;
                }
                string uploadDir = Path.GetDirectoryName(function.VToP(uploadPath));
                if (!Directory.Exists(uploadDir))
                {
                    SafeSC.CreateDir(function.PToV(uploadDir));
                }
                if (action.Equals("Plat_Doc") || action.Equals("Plat_Doc_Common"))
                {
                    #region 能力中心文档
                    M_Plat_File fileMod = new M_Plat_File();
                    B_Plat_File fileBll = new B_Plat_File();
                    fileMod.FileName  = file.FileName;
                    fileMod.SFileName = function.GetRandomString(12) + Path.GetExtension(file.FileName);
                    fileMod.VPath     = uploadPath.Replace("//", "/");
                    fileMod.UserID    = upMod.UserID.ToString();
                    fileMod.CompID    = upMod.CompID;
                    //SafeSC.SaveFile(uploadPath, file, fileMod.SFileName);
                    fileMod.FileSize = new FileInfo(ppath + fileMod.SFileName).Length.ToString();
                    fileBll.Insert(fileMod);
                    #endregion
                }
                else if (action.Equals("Cloud_Doc"))
                {
                    #region 用户中心云盘
                    if (!buser.CheckLogin())
                    {
                        throw new Exception("云盘,用户未登录");
                    }
                    M_User_Cloud cloudMod = new M_User_Cloud();
                    B_User_Cloud cloudBll = new B_User_Cloud();
                    uploadPath         = HttpUtility.UrlDecode(cloudBll.H_GetFolderByFType(GetParam("type"), mu)) + GetParam("value");
                    cloudMod.FileName  = file.FileName;
                    cloudMod.SFileName = function.GetRandomString(12) + Path.GetExtension(file.FileName);
                    cloudMod.VPath     = (uploadPath + "/").Replace("//", "/");
                    cloudMod.UserID    = mu.UserID;
                    cloudMod.FileType  = 1;
                    //result = SafeSC.SaveFile(cloudMod.VPath, file, cloudMod.SFileName);
                    //if (SafeSC.IsImage(cloudMod.SFileName))
                    //{
                    //    string icourl = SiteConfig.SiteOption.UploadDir + "YunPan/" + mu.UserName + mu.UserID + "/ico" + value + "/";
                    //    if (!Directory.Exists(function.VToP(icourl))) { SafeSC.CreateDir(icourl); }
                    //    ImgHelper imghelp = new ImgHelper();
                    //    imghelp.CompressImg(file, 100, icourl + cloudMod.SFileName);
                    //}
                    cloudMod.FileSize = new FileInfo(function.VToP(cloudMod.VPath) + cloudMod.SFileName).Length.ToString();
                    cloudBll.Insert(cloudMod);
                    #endregion
                }
                else
                {
                    //string fname = CreateFName(file.FileName);
                    //if (SafeC.IsImageFile(file.FileName) && file.Length > (5 * 1024 * 1024))//图片超过5M则压缩
                    //{
                    //    result = uploadPath + function.GetRandomString(6) + fname;
                    //    new ImgHelper().CompressImg(file, 5 * 1024, result);
                    //}
                    //else
                    //{
                    result = SafeC.SaveFile(uploadPath, filename, file.OpenReadStream(), (int)file.Length);
                    //}
                    //添加水印
                    //if (WaterModuleConfig.WaterConfig.EnableUserWater)
                    //{
                    //    //未以管理员身份登录,并有会员身份登录记录
                    //    if (adminMod == null && !mu.IsNull)
                    //    {
                    //        Image img = WaterImages.DrawFont(ImgHelper.ReadImgToMS(result), mu.UserName + " " + DateTime.Now.ToString("yyyy/MM/dd"), 9);
                    //        ImgHelper.SaveImage(result, img);
                    //    }
                    //}
                    //else if (DataConverter.CStr(context.Request["IsWater"]).Equals("1"))
                    //{
                    //    //前台主动标识需要使用水印
                    //    result = ImgHelper.AddWater(result);
                    //}
                }
                ZLLog.L(ZLEnum.Log.fileup, new M_Log()
                {
                    UName   = mu.UserName,
                    Source  = Request.RawUrl(),
                    Message = "上传成功|文件名:" + file.FileName + "|" + "保存路径:" + uploadPath
                });
            }
            catch (Exception ex)
            {
                ZLLog.L(ZLEnum.Log.fileup, new M_Log()
                {
                    UName   = mu.UserName,
                    Source  = Request.RawUrl(),
                    Message = "上传失败|文件名:" + file.FileName + "|" + "原因:" + ex.Message
                });
            }
            return(Content(result));
        }
Beispiel #9
0
        public string SaveFile()
        {
            C_SFileUP          model  = JsonConvert.DeserializeObject <C_SFileUP>(Request.Form["model"]);
            HttpPostedFileBase file   = Request.Files["file"];
            string             result = "";

            if (file.ContentLength < 100 || string.IsNullOrEmpty(file.FileName))
            {
                return("");
            }
            string fname = DateTime.Now.ToString("yyyyMMddHHmm") + function.GetRandomString(4) + Path.GetExtension(file.FileName);

            switch (model.FileType)
            {
            case "img":
            {
                // function.WriteErrMsg(Path.GetExtension(file.FileName) + "不是有效的图片格式!");
                if (!SafeSC.IsImage(file.FileName))
                {
                    return("");
                }
                ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                if (model.MaxWidth > 0 || model.MaxHeight > 0)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                    img     = imghelp.ZoomImg(img, model.MaxHeight, model.MaxWidth);
                    result  = ImgHelper.SaveImage(GetSaveDir(model.SaveType) + fname, img);
                    hasSave = true;
                }
                if (!hasSave)
                {
                    result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
                }
            }
            break;

            case "office":
            {
                string[] exname = "doc|docx|xls|xlsx".Split('|');
                if (!exname.Contains(Path.GetExtension(file.FileName)))
                {
                    function.WriteErrMsg("必须上传doc|docx|xls|xlsx格式的文件!"); return("");
                }
                // result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
            }
            break;

            case "all":
            default:
            {
                // result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, file.InputStream, file.ContentLength);
            }
            break;
            }
            return(result);
        }