Exemplo n.º 1
0
        public bool UploadWordSwfUpload(out string message, out string fileName)
        {
            message = fileName = string.Empty;

            if (Request.Files["Filedata"] == null)
            {
                return(false);
            }
            var postedFile = Request.Files["Filedata"];

            try
            {
                fileName = postedFile.FileName;
                var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                if (extendName == ".doc" || extendName == ".docx")
                {
                    var filePath = WordUtils.GetWordFilePath(fileName);
                    postedFile.SaveAs(filePath);
                    return(true);
                }
                message = "请选择Word文件上传!";
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
Exemplo n.º 2
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var fileNames = Request.Form["fileNames"];

            if (!string.IsNullOrEmpty(fileNames))
            {
                fileNames = fileNames.Trim('|');
                var builder = new StringBuilder();

                foreach (var fileName in fileNames.Split('|'))
                {
                    var filePath    = WordUtils.GetWordFilePath(fileName);
                    var wordContent = WordUtils.Parse(SiteId, filePath, CbIsClearFormat.Checked, CbIsFirstLineIndent.Checked, CbIsClearFontSize.Checked, CbIsClearFontFamily.Checked, CbIsClearImages.Checked);
                    wordContent = ContentUtility.TextEditorContentDecode(SiteInfo, wordContent, true);
                    builder.Append(wordContent);
                    FileUtils.DeleteFileIfExists(filePath);
                }
                var script = "parent." + ETextEditorTypeUtils.GetInsertHtmlScript(_attributeName, builder.ToString());
                LayerUtils.CloseWithoutRefresh(Page, script);
            }
            else
            {
                FailMessage("请选择Word文件上传!");
            }
        }
Exemplo n.º 3
0
        protected override object Process()
        {
            var fileName = AuthRequest.HttpRequest["fileName"];

            var fileCount = AuthRequest.HttpRequest.Files.Count;

            string filePath = null;

            if (fileCount > 0)
            {
                var file = AuthRequest.HttpRequest.Files[0];

                //var fileName = Path.GetFileName(file.FileName);
                //var path = context.Server.MapPath("~/upload/" + fileName);

                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = Path.GetFileName(file.FileName);
                }

                var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                if (extendName == ".doc" || extendName == ".docx")
                {
                    filePath = WordUtils.GetWordFilePath(fileName);
                    file.SaveAs(filePath);
                }
            }

            return(GetResponseObject(fileName, filePath));
        }
Exemplo n.º 4
0
        private Hashtable Upload()
        {
            var success  = false;
            var fileName = string.Empty;
            var message  = "Word上传失败";

            if (Request.Files["filedata"] != null)
            {
                var postedFile = Request.Files["filedata"];
                try
                {
                    if (!string.IsNullOrEmpty(postedFile?.FileName))
                    {
                        fileName = postedFile.FileName;
                        var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                        if (extendName == ".doc" || extendName == ".docx")
                        {
                            var filePath = WordUtils.GetWordFilePath(fileName);
                            postedFile.SaveAs(filePath);

                            success = true;
                        }
                        else
                        {
                            FailMessage("请选择Word文件上传!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                }
            }

            var jsonAttributes = new Hashtable();

            if (success)
            {
                jsonAttributes.Add("success", "true");
                jsonAttributes.Add("fileName", fileName);
            }
            else
            {
                jsonAttributes.Add("success", "false");
                jsonAttributes.Add("message", message);
            }

            return(jsonAttributes);
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            var body = new Request();

            if (!body.IsAdminLoggin)
            {
                return;
            }

            var request = context.Request;

            var action   = request["action"];
            var hash     = request["hash"];
            var fileName = request["fileName"];

            var fileCount = request.Files.Count;

            string filePath = null;

            if (string.IsNullOrEmpty(hash))
            {
                //普通上传
                if (fileCount > 0)
                {
                    var file = request.Files[0];

                    //var fileName = Path.GetFileName(file.FileName);
                    //var path = context.Server.MapPath("~/upload/" + fileName);

                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = Path.GetFileName(file.FileName);
                    }

                    var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                    if (extendName == ".doc" || extendName == ".docx")
                    {
                        filePath = WordUtils.GetWordFilePath(fileName);
                        file.SaveAs(filePath);
                    }
                }
            }
            else
            {
                //秒传或断点续传
                //var path = context.Server.MapPath("~/upload/" + hash);
                var path   = WordUtils.GetWordFilePath(hash);
                var pathOk = path + Path.GetExtension(fileName);

                //状态查询
                if (action == "query")
                {
                    if (File.Exists(pathOk))
                    {
                        Finish(GetResponseJson(fileName, pathOk));
                    }
                    else if (File.Exists(path))
                    {
                        Finish(new FileInfo(path).Length.ToString());
                    }
                    else
                    {
                        Finish("0");
                    }
                }
                else
                {
                    if (fileCount > 0)
                    {
                        var file = request.Files[0];
                        using (var fs = File.Open(path, FileMode.Append))
                        {
                            byte[] buffer = new byte[file.ContentLength];
                            file.InputStream.Read(buffer, 0, file.ContentLength);

                            fs.Write(buffer, 0, buffer.Length);
                        }
                    }

                    var isOk = request["ok"] == "1";
                    if (!isOk)
                    {
                        Finish("1");
                    }

                    if (File.Exists(path))
                    {
                        File.Move(path, pathOk);
                    }
                }
            }

            Finish(GetResponseJson(fileName, filePath));
        }