

Navigator : Home > Tutorials > Advanced Technologies Tutorials > ...
Manipulate external app using ASP.NET 2.0 and VB.NET
This tutorial will use WinRAR as an example to show you how to excute an outside application process by using ASP.NET 2.0 and VB.NET. We will manipulate WinRAR command to compress or extract file.
This tutorial will use WinRAR as an example to show you how to excute an outside application process by using ASP.NET 2.0 and C#. We will manipulate WinRAR command to compress or extract file.
At first, you need to import the namespace from Microsoft.Win32 and System.Diagnostics.RegistryKey and Registry class in the namespace Microsoft.Win32.Class RegistryKey represents a key-level node in the Windows registry, which is a registry encapsulation.Class Registry Supplies the base Registrykeys that access values and subkeys in the registry.ProcessStartInfo and Process class in the namespace System.Diagnostics. ProcessStartInfo is used in conjunction with the Process component. When you start a process using the Process class, you have access to process information in addition to that available when attaching to a running process.Process provides access to local and remote processes and enables you to start and stop local system processes.
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
Imports Microsoft.Win32; Imports System.Diagnostics; |
In order to run the example, please create a file under the directory c:\test\test.txt. Run the example and click Zip button you will see a compressed file test.rar will be generated in the c:\test .Click UnZip button you will see that the test.rar will be extracted. Button1_Click event is used to zip a file and Button2_Click is used to unzip a file. The following code is:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim the_rar As String Dim the_Reg As RegistryKey Dim the_Obj As Object Dim the_Info As String Dim the_StartInfo As ProcessStartInfo Dim the_Process As Process Try
the_Reg = Registry.ClassesRoot.OpenSubKey("Applications\WinRAR.exe\Shell\Open\Command") the_Obj = the_Reg.GetValue("") the_rar = the_Obj.ToString() the_Reg.Close() the_rar = the_rar.Substring(1, the_rar.Length - 7) the_Info = " a " + " test.rar " + " " + "C:\test\test.txt" the_StartInfo = New ProcessStartInfo()
the_StartInfo.FileName = the_rar the_StartInfo.Arguments = the_Info the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden the_StartInfo.WorkingDirectory = "C:\test\" the_Process = New Process() the_Process.StartInfo = the_StartInfo the_Process.Start() Response.Write("<script>alert('Zip Successfully');</script>") Catch ex As Exception
Response.Write("<script>alert('Zip Failed.')</script>") End Try End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com ' Visit http://www.DotNetTutorials.com for more ASP.NET Tutorials End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim the_rar As String Dim the_Reg As RegistryKey Dim the_Obj As Object Dim the_Info As String Dim the_StartInfo As ProcessStartInfo Dim the_Process As Process Try
the_Reg = Registry.ClassesRoot.OpenSubKey("Applications\WinRAR.exe\Shell\Open\Command") the_Obj = the_Reg.GetValue("") the_rar = the_Obj.ToString() the_Reg.Close() the_rar = the_rar.Substring(1, the_rar.Length - 7) the_Info = " X " + " test.rar " + " " + "C:\test" the_StartInfo = New ProcessStartInfo()
the_StartInfo.FileName = the_rar the_StartInfo.Arguments = the_Info the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden the_StartInfo.WorkingDirectory = "C:\test\" the_Process = New Process() the_Process.StartInfo = the_StartInfo the_Process.Start() Response.Write("<script>alert('Zip Successfully');</script>") Catch ex As Exception
Response.Write("<script>alert('Zip Failed.')</script>") End Try End Sub |
The front end page looks something like this:
| <div align="center">
<asp:Button ID="Button1" runat="server" Text="Zip" Width="71px" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="UnZip" Width="76px" OnClick="Button2_Click" /> </div> |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
The flow for the code behind page is as follows:
Imports Microsoft.Win32 Imports System.Diagnostics
Partial Class _Default
Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim the_rar As String Dim the_Reg As RegistryKey Dim the_Obj As Object Dim the_Info As String Dim the_StartInfo As ProcessStartInfo Dim the_Process As Process Try
the_Reg = Registry.ClassesRoot.OpenSubKey("Applications\WinRAR.exe\Shell\Open\Command") the_Obj = the_Reg.GetValue("") the_rar = the_Obj.ToString() the_Reg.Close() the_rar = the_rar.Substring(1, the_rar.Length - 7) the_Info = " a " + " test.rar " + " " + "C:\test\test.txt" the_StartInfo = New ProcessStartInfo()
the_StartInfo.FileName = the_rar the_StartInfo.Arguments = the_Info the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden the_StartInfo.WorkingDirectory = "C:\test\" the_Process = New Process() the_Process.StartInfo = the_StartInfo the_Process.Start() Response.Write("<script>alert('Zip Successfully');</script>") Catch ex As Exception
Response.Write("<script>alert('Zip Failed.')</script>") End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim the_rar As String Dim the_Reg As RegistryKey Dim the_Obj As Object Dim the_Info As String Dim the_StartInfo As ProcessStartInfo Dim the_Process As Process Try
the_Reg = Registry.ClassesRoot.OpenSubKey("Applications\WinRAR.exe\Shell\Open\Command") the_Obj = the_Reg.GetValue("") the_rar = the_Obj.ToString() the_Reg.Close() the_rar = the_rar.Substring(1, the_rar.Length - 7) the_Info = " X " + " test.rar " + " " + "C:\test" the_StartInfo = New ProcessStartInfo()
the_StartInfo.FileName = the_rar the_StartInfo.Arguments = the_Info the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden the_StartInfo.WorkingDirectory = "C:\test\" the_Process = New Process() the_Process.StartInfo = the_StartInfo the_Process.Start() Response.Write("<script>alert('Zip Successfully');</script>") Catch ex As Exception
Response.Write("<script>alert('Zip Failed.')</script>") End Try End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.