public ActionResult rcjc() { Response resp = new Response(); string id = Request.Form["id"]; string date = Request.Form["date"]; int projectID = int.Parse(id); Project project = projectManager.Find(projectID); project.CheckTime = DateTime.Parse(date); project.Progress = ProjectProgress.入场检测; if (Request.Files.Count == 0) { resp.Code = -1; resp.Message = "上传文件不能为空"; return(Json(resp)); } var file = Request.Files[0]; if (file.ContentLength >= 20971520) { resp.Code = -2; resp.Message = "上传文件太大"; return(Json(resp)); } var fileName = file.FileName; if (fileName.Substring(fileName.Length - 4, 4) != ".rar") { resp.Code = -3; resp.Message = "文件格式不符合要求"; return(Json(resp)); } fileName = Verification.Text(20) + ".rar"; var filePath = Server.MapPath("~/Upload/Datas"); var path = string.Format(filePath + "\\{0}", fileName); file.SaveAs(path); Model.UploadFile f = new Model.UploadFile(); f.Name = fileName; f.Path = "~/Upload/Datas/" + fileName; var res = fileManager.Add(f); project.DataFile = f; projectManager.Update(project); return(Json(resp)); }
public string Run(string file) { if (d != null) { if (d.inputType == Db.uploadInputType.custom) file = d.customFileToUpload; string method = "POST"; if(d.method == Db.uploadMethod.GET) method = "GET"; if(d.method == Db.uploadMethod.PUT) method = "PUT"; if (d.usePostData) { Model.UploadFile f = new Model.UploadFile(); FileInfo finfo = new FileInfo(file); f.Filename = file; f.Stream = File.Open(file, FileMode.Open); f.ContentType = MimeTypeUtils.GetMimeType(finfo.Extension); f.Name = finfo.Name; List< Model.UploadFile> files = new List<Model.UploadFile>(); files.Add(f); //add post params NameValueCollection values = new NameValueCollection(); foreach (Db.uploadPostData p in d.postData) values.Add(p.key, p.value); string res = HttpUtils.UploadFiles(d.uploadUrl,files, values); f.Stream.Close(); return res; } else return HttpUtils.uploadFileSimple(d.uploadUrl, file, d.customUserAgent, d.customHttpHeadersInfo, method); } return string.Empty; ; }
public ActionResult cjbg() { Response resp = new Response(); string id = Request.Form["id"]; int projectID = int.Parse(id); Project project = projectManager.Find(projectID); if (Request.Files.Count == 0) { resp.Code = -1; resp.Message = "上传文件不能为空"; return(Json(resp)); } var file = Request.Files[0]; if (file.ContentLength >= 52428800) { resp.Code = -2; resp.Message = "上传文件太大"; return(Json(resp)); } var fileName = file.FileName; if (fileName.Substring(fileName.Length - 4, 4) != ".pdf") { resp.Code = -3; resp.Message = "文件格式不符合要求"; return(Json(resp)); } var filePath = Server.MapPath("~/Upload/Reports"); var path = string.Format(filePath + "\\{0}", fileName); file.SaveAs(path); fileName = Verification.Text(20) + ".pdf"; string inputfilepath = path; string outputfilepath = string.Format(filePath + "\\{0}", fileName); string waterMarkName = "查询码:" + project.ReportFileCode; string pngpath = Server.MapPath("~/Content/img/waterprint_09.png"); PdfReader pdfReader = null; PdfStamper pdfStamper = null; try { pdfReader = new PdfReader(inputfilepath); pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create)); int total = pdfReader.NumberOfPages + 1; iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1); float width = psize.Width; float height = psize.Height; PdfContentByte content; BaseFont font = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfGState gs = new PdfGState(); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(pngpath); image.SetAbsolutePosition(width / 2 - image.Width / 2, height / 2 - image.Height / 2); for (int i = 1; i < total; i++) { content = pdfStamper.GetOverContent(i);//在内容上方加水印 //content = pdfStamper.GetUnderContent(i);//在内容下方加水印 //透明度 content.AddImage(image); content.SetGState(gs); //content.SetGrayFill(0.3f); //开始写入文本 content.BeginText(); content.SetColorFill(BaseColor.BLUE); content.SetFontAndSize(font, width / 40); content.SetTextMatrix(0, 0); content.ShowTextAligned(Element.ALIGN_RIGHT, waterMarkName, width, height - height / 40, 0); //content.SetColorFill(BaseColor.BLACK); //content.SetFontAndSize(font, 8); //content.ShowTextAligned(Element.ALIGN_CENTER, waterMarkName, 0, 0, 0); content.EndText(); } } catch (Exception ex) { throw ex; } finally { if (pdfStamper != null) { pdfStamper.Close(); } if (pdfReader != null) { pdfReader.Close(); } } System.IO.File.Delete(inputfilepath); Model.UploadFile f = new Model.UploadFile(); f.Name = fileName; f.Path = "~/Upload/Reports/" + f.Name; var res = fileManager.Add(f); project.ReportFile = f; project.Progress = ProjectProgress.出具报告; projectManager.Update(project); return(Json(resp)); }