protected void Page_Load(object sender, EventArgs e) { UserPdfFileInfo pdf = new UserPdfFileInfo(); BllPdfFileInfoMangr bpfm = new BllPdfFileInfoMangr(); var msg=string.Empty; pdf.createTime = DateTime.Now; pdf.pdfFileAuthor = "xia"; pdf.pdfFileName = "xia.pdf"; pdf.pdfFileID = Guid.NewGuid().ToString(); if (!bpfm.AddPdfFileInfo(pdf,out msg)) { var x = msg; } }
protected void Page_Load(object sender, EventArgs e) { var uID = string.Empty; var extName = string.Empty; var pdfPath = Config.ReadSetting("SourcePath", ""); var fileName = string.Empty; if (Request["uid"] == null && Request["uid"] == "") { ResultDataMangr reData = new ResultDataMangr() { result = false, errCode = "用户名为空!" }; OutPut(reData); } uID = Request["uid"].ToString(); var fileData = Request.Files["FileData"]; ApplicationLog.WriteInfo("uid="+uID); if (fileData != null) { extName = fileData.FileName.Substring(fileData.FileName.LastIndexOf(".")).ToLower(); var fileType = Config.ReadSetting("SourceFileter", ""); if (!fileType.ToString().Contains(extName)) { ResultDataMangr reData = new ResultDataMangr() { result = false, errCode = "文件类型错误,不支持该类型文件上传!" }; OutPut(reData); } pdfPath =Server.MapPath("../pdfFile/source/") + uID; ApplicationLog.WriteInfo("pdfPath:"+pdfPath); if (!Directory.Exists(pdfPath)) { Directory.CreateDirectory(pdfPath); } //DirectoryInfo dirInfo = new DirectoryInfo(pdfPath); //dirInfo.CreateSubdirectory(uID); fileName = fileData.FileName.Substring(0,fileData.FileName.LastIndexOf("."))+"-"+ DateTime.Now.Ticks.ToString(); var filePath=pdfPath + "\\" + fileName + extName; fileData.SaveAs(filePath);//保存图片 //往数据添加文件数据 var msg=string.Empty; UserPdfFileInfo pdf = new UserPdfFileInfo(); BllPdfFileInfoMangr bpfm = new BllPdfFileInfoMangr(); pdf.pdfFileID = Guid.NewGuid().ToString(); pdf.pdfFileAuthor = uID; pdf.pdfUserName = uID; pdf.pdfFileName = fileName; pdf.createTime = DateTime.Now.ToString("yyyy-MM-dd"); pdf.pdfPath = filePath; if (!bpfm.AddPdfFileInfo(pdf, out msg)) { msg = "往数据库写数据失败!"; ApplicationLog.WriteError(msg); } ResultDataMangr resultData=new ResultDataMangr(){result=true,title=fileName,author=uID,time=pdf.createTime}; var strData=pdf2String(resultData); ApplicationLog.WriteInfo("上传成功,Info"+strData); var strHtml = "<script type=\"text/javascript\">window.parent.Bing.templateData='"+strData+"'</script>"; Context.Response.Write(strHtml); Context.Response.End(); } }
public string Upload(string documentURL, string uid) { bool isParameterError = false; string errorMessage = string.Empty; if (String.IsNullOrEmpty(documentURL) || Helper.IsURL(documentURL) == false) { isParameterError = true; errorMessage = "文档地址不能为空,且必须是合法的URL格式"; } if (String.IsNullOrEmpty(uid)) { isParameterError = true; errorMessage = "请提供用户名"; } if (Helper.GetDocType(documentURL) == EnumDocType.Other) { isParameterError = true; errorMessage = "只允许上传 .doc /.docx /.xls /.ppt /.pdf /.txt 文件"; } if (isParameterError) { return resultData2String(new ResultDataMangr() { result = false, errCode = errorMessage }); } string GUID = System.Guid.NewGuid().ToString(); string pdfPath = Config.ReadSetting("SourcePath", string.Empty); string sourceFileName = System.IO.Path.GetFileName(documentURL); string saveFileName = GUID + ".pdf"; pdfPath = Server.MapPath("~/pdfFile/source/") + uid; if (!Directory.Exists(pdfPath)) Directory.CreateDirectory(pdfPath); // 存储pdf文件的名称 string savePath = pdfPath + "\\" + saveFileName; // office文档转化成PDF并保存 string convertErrorMsg = string.Empty; if (!DocToPDFFActory.DocToPDF(new ConvertParameter() { SourcePath = documentURL, IsAllPage = true, TargetPath = savePath, StartPage = 1, EndPage = 1 }, out convertErrorMsg)) { return resultData2String(new ResultDataMangr() { result = false, errCode = convertErrorMsg //"转化成PDF时出现错误,请确认URL是Office文档并且可访问" }); } // 添加文件信息到数据库 UserPdfFileInfo pdf = new UserPdfFileInfo() { pdfFileID = GUID, pdfFileAuthor = uid, pdfUserName = uid, pdfFileName = System.IO.Path.GetFileName(documentURL), createTime = DateTime.Now,//时区 pdfPath = savePath }; string msg = string.Empty; if (!new BllPdfFileInfoMangr().AddPdfFileInfo(pdf, out msg)) { ApplicationLog.WriteError("写入数据库错误:" + msg); } return resultData2String(new ResultDataMangr() { result = true, title = System.IO.Path.GetFileName(documentURL), fileID = pdf.pdfFileID, author = uid, time = pdf.createTime.ToString() }); }