ASP. NET extract File class online

Source: Internet
Author: User

  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Text;
  4. Using System.IO;
  5. Using Microsoft.Win32;
  6. Using System.Diagnostics;
  7. Using System.Web;
  8. public class Winrar
  9. {
  10. // <summary>
  11. /// whether the WinRAR is installed
  12. // </summary>
  13. // <returns></returns>
  14. static public bool Exists ()
  15. {
  16. RegistryKey The_reg = Registry.LocalMachine.OpenSubKey (@"Software/microsoft/windows/currentversion/app paths/  WinRAR.exe ");
  17. return! string. IsNullOrEmpty (The_reg.getvalue ("").  ToString ());
  18. }
  19. // <summary>
  20. /// package into RAR
  21. // </summary>
  22. /// <param name= "Patch" ></param>
  23. /// <param name= "Rarpatch" ></param>
  24. /// <param name= "Rarname" ></param>
  25. public string Compressrar (string patch, string rarpatch, string rarname)
  26. {
  27. string The_rar;
  28. RegistryKey The_reg;
  29. object the_obj;
  30. string The_info;
  31. ProcessStartInfo The_startinfo;
  32. Process the_process;
  33. Try
  34. {
  35. The_reg = Registry.LocalMachine.OpenSubKey (@"Software/microsoft/windows/currentversion/app paths/winrar.exe")  ;
  36. The_obj = The_reg.getvalue ("");
  37. The_rar = The_obj.tostring ();
  38. The_reg.close ();
  39. The_rar = The_rar. Substring (1, The_rar. LENGTH-7);
  40. Directory.CreateDirectory (patch);
  41. //Command Parameters
  42. //the_info = "a" + Rarname + "" + @ "C:test?70821.txt"; File Compression
  43. The_info = "a" + Rarname + "" + Patch + "-r";;
  44. The_startinfo = new ProcessStartInfo ();
  45. The_startinfo.filename = The_rar;
  46. The_startinfo.arguments = The_info;
  47. The_startinfo.windowstyle = Processwindowstyle.hidden;
  48. //package file storage directory
  49. The_startinfo.workingdirectory = Rarpatch;
  50. the_process = new Process ();
  51. The_process.startinfo = The_startinfo;
  52. The_process.start ();
  53. The_process.waitforexit ();
  54. The_process.close ();
  55. }
  56. catch (Exception ex)
  57. {
  58. return ex.  Message;
  59. }
  60. return string.  Empty;
  61. }
  62. // <summary>
  63. // Decompression
  64. // </summary>
  65. /// <param name= "Unrarpatch" ></param>
  66. /// <param name= "Rarpatch" ></param>
  67. /// <param name= "Rarname" ></param>
  68. // <returns></returns>
  69. public string Uncompressrar (string unrarpatch, string rarpatch, string rarname)
  70. {
  71. string The_rar;
  72. RegistryKey The_reg;
  73. object the_obj;
  74. string The_info;
  75. Try
  76. {
  77. The_reg = Registry.LocalMachine.OpenSubKey (@"Software/microsoft/windows/currentversion/app paths/winrar.exe")  ;
  78. The_obj = The_reg.getvalue ("");
  79. The_rar = The_obj.tostring ();
  80. The_reg.close ();
  81. //the_rar = The_rar. Substring (1, The_rar.  LENGTH-7);
  82. if (directory.exists (unrarpatch) = = false)
  83. {
  84. Directory.CreateDirectory (Unrarpatch);
  85. }
  86. The_info = "x/""+ Rarname +"/"/""+ Unrarpatch +"/"-y";
  87. ProcessStartInfo the_startinfo = new ProcessStartInfo ();
  88. The_startinfo.filename = The_rar;
  89. The_startinfo.arguments = The_info;
  90. The_startinfo.windowstyle = Processwindowstyle.hidden;
  91. The_startinfo.workingdirectory = Rarpatch; //Get compressed package path
  92. Process the_process = new Process ();
  93. The_process.startinfo = The_startinfo;
  94. The_process.start ();
  95. The_process.waitforexit ();
  96. The_process.close ();
  97. }
  98. catch (Exception ex)
  99. {
  100. return ex.  Message;
  101. }
  102. return string.  Empty;
  103. }
  104. }

ASP. NET extract File class online

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.