zoukankan      html  css  js  c++  java
  • backup1

     1 string _imgpath1 = WebConfigurationManager.AppSettings["IMGPATH1"].ToString();
     2 
     3 string outputPath = Server.MapPath(Request.ApplicationPath + "/output");
     4 string file = Guid.NewGuid().ToString() + ".pdf";
     5 string desFile = Path.Combine(outputPath, file);
     6 
     7 string relativepath = "output/" + file;
     8 
     9 //转义
    10 //System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312");
    11 //string encodeFilePath = _imgpath1 + HttpUtility.UrlEncode(_imgpath2 + genre, gb2312).Replace("%2f", "/").Replace("%5c", "/").Replace("+", "%20");
    12 
    13 
    14 
    15 
    16 
    17 private void DownloadFile(string userName, string password, string ftpSourceFilePath, string localDestinationFilePath)
    18 {
    19   int bytesRead = 0;
    20   byte[] buffer = new byte[2048];
    21 
    22   FtpWebRequest request = CreateFtpWebRequest(ftpSourceFilePath, userName, password, true);
    23   request.Method = WebRequestMethods.Ftp.DownloadFile;
    24 
    25   Stream reader = request.GetResponse().GetResponseStream();
    26   FileStream fileStream = new FileStream(localDestinationFilePath, FileMode.Create);
    27 
    28   while (true)
    29   {
    30     bytesRead = reader.Read(buffer, 0, buffer.Length);
    31 
    32     if (bytesRead == 0)
    33       break;
    34 
    35     fileStream.Write(buffer, 0, bytesRead);
    36   }
    37   fileStream.Close();
    38 }
    39 private FtpWebRequest CreateFtpWebRequest(string ftpDirectoryPath, string userName, string password, bool keepAlive = false)
    40 {
    41   FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpDirectoryPath));
    42 
    43   //Set proxy to null. Under current configuration if this option is not set then the proxy that is used will get an html response from the web content gateway (firewall monitoring system)
    44   request.Proxy = null;
    45 
    46   request.UsePassive = true;
    47   request.UseBinary = true;
    48   request.KeepAlive = keepAlive;
    49 
    50   request.Credentials = new NetworkCredential(userName, password);
    51 
    52   return request;
    53 }
    54 
    55 
    56 
    57 
    58 
    59 try
    60 {
    61 string template = Server.MapPath(Request.ApplicationPath + "/reporttemplate/国有土地使用证.mrt");
    62 string outputPath = Server.MapPath(Request.ApplicationPath + "/output");
    63 //删除过期的临时PDF文件
    64 List<FileInfo> toDeleteFiles = new List<FileInfo>();
    65 Directory.GetFiles(outputPath, "*.pdf").ToList().ForEach(i => {
    66 if ((new FileInfo(i)).CreationTime < DateTime.Now)
    67 toDeleteFiles.Add(new FileInfo(i));
    68 });
    69 Task task = new Task(() =>
    70 {
    71 for (int i = toDeleteFiles.Count - 1; i >= 0; i--)
    72 { toDeleteFiles[i].Delete(); }
    73 });
    74 task.Start();
    75 
    76 StiReport report = new StiReport();
    77 report.Load(template);
    78 report.RegBusinessObject("land", "cer", cer);
    79 report.Compile();
    80 report.Render(true);
    81 string file = Guid.NewGuid().ToString() + ".pdf";
    82 string relativepath = "/output/" + file;
    83 string fullpath = Path.Combine(outputPath, file);
    84 report.ExportDocument(StiExportFormat.Pdf, fullpath);
    85 
    86 
    87 return View(new PdfEntity() { Filename = fullpath, RelativeFilename = relativepath });
    88 }
    89 catch (Exception ex)
    90 {
    91 return View("Error", new HandleErrorInfo(ex, "CerController转换为PDF文件时发生异常", "Index"));
    92 }
    View Code
    @model LandRegQueryWeb.Models.PdfEntity
    @{
        Layout = null;
    }
    
    <html>
    <body style="background-color: rgb(38,38,38); height: 100%;  100%; overflow: hidden; margin: 0">
    
        <embed width="100%" height="100%"
               name="plugin" id="plugin"
               src="@Model.Filename#toolbar=0&navpanes=0&scrollbar=0"
               type="application/pdf" internalinstanceid="3" title="">
    
    </body>
    </html>
    View Code
  • 相关阅读:
    01快速入门-03-条件判断和循环
    01快速入门-02-数组和对象
    01快速入门-01-基本语法和数据类型
    《Head First 设计模式》[01] 策略模式
    爬山算法与模拟退火算法的分析与实现
    Java虚拟机(二) —— 运行时数据区的OOM异常
    CoreJava(一)—— Java迭代语句
    Java虚拟机(二) —— 垃圾回收算法与垃圾回收器
    算法学习 —— 使用Linux C++练习OJ
    Java虚拟机(一) —— 运行时数据区
  • 原文地址:https://www.cnblogs.com/yansc/p/6077342.html
Copyright © 2011-2022 走看看