18.2. Executing External Applications
Problem
You need to run an external application from your web application to perform a required operation.
Solution
Use the System.Diagnostics.Process.Start
method to
call your external application.
In the code-behind class for the page, use the .NET language of your choice to:
Import the
System.Diagnostics
namespace.Create a
ProcessStartInfo
object, passing the name of the external application to run along with any required command-line parameters.Set the working directory to the location of the external application.
Start the external application process by calling the
Start
method of theProcess
class, passing theProcessStartInfo
object.
Example 18-3 and Example 18-4 show the relevant portion of the sample VB and C# code-behind files that illustrate this solution.
Discussion
Applications frequently must interface with other applications or systems that use different technologies. At the same time, it is not always practical to migrate these applications to the new platforms or to provide web service wrappers to gain access to the applications. Sometimes, the only practical solution is to execute another program to perform the required operation. For example, you may have an existing application that exports data from your Cobol accounting program to a format usable by other systems. The common language runtime (CLR) provides a set of classes to support running other applications from within the .NET environment. These classes are part of the
Get ASP.NET Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.