Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:59:48+00:00 2026-05-24T03:59:48+00:00

I need some advice regarding the use of a command line utility from a

  • 0

I need some advice regarding the use of a command line utility from a C#/ASP.NET web application.

I found a 3rd party utility for converting files to CSV format. The utility works perfectly and it can be used from the command line.

I have been looking on the web for examples on how to execute the command line utility and found this example.

The problem is this is not very good. When I try to us the example code with my utility, I get a prompt asking me to install the utility on the client machine. This is not what I want. I do not want the user to see what is going on in the background.

Is it possible to execute the command server side and processing the file from there?

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:59:49+00:00Added an answer on May 24, 2026 at 3:59 am

    I’ve done something like this several times in the past, and here’s what’s worked for me:

    Create an IHttpHandler implementation (easiest to do as an .ashx file) to handle a convert. Within the handler, use System.Diagnostics.Process and ProcessStartInfo to run your command line utility. You should be able to redirect the standard output to the output stream of your HTTP response. Here’s some code:

    public class ConvertHandler : IHttpHandler
    {
        #region IHttpHandler Members
    
        bool IHttpHandler.IsReusable
        {
            get { return false; }
        }
    
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            var jobID = Guid.NewGuid();
    
            // retrieve the posted csv file
            var csvFile = context.Request.Files["csv"]; 
    
            // save the file to disk so the CMD line util can access it
            var filePath = Path.Combine("csv", String.Format("{0:n}.csv", jobID));
            csvFile.SaveAs(filePath);
    
            var psi = new ProcessStartInfo("mycsvutil.exe", String.Format("-file {0}", filePath))
            {
                WorkingDirectory = Environment.CurrentDirectory,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true                
            };
    
            using (var process = new Process { StartInfo = psi })
            {
                // delegate for writing the process output to the response output
                Action<Object, DataReceivedEventArgs> dataReceived = ((sender, e) =>
                {
                    if (e.Data != null) // sometimes a random event is received with null data, not sure why - I prefer to leave it out
                    {
                        context.Response.Write(e.Data);
                        context.Response.Write(Environment.NewLine);
                        context.Response.Flush();
                    }
                });
    
                process.OutputDataReceived += new DataReceivedEventHandler(dataReceived);
                process.ErrorDataReceived += new DataReceivedEventHandler(dataReceived);
    
                // use text/plain so line breaks and any other whitespace formatting is preserved
                context.Response.ContentType = "text/plain";
    
                // start the process and start reading the standard and error outputs
                process.Start();
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
    
                // wait for the process to exit
                process.WaitForExit();
    
                // an exit code other than 0 generally means an error
                if (process.ExitCode != 0)
                {
                    context.Response.StatusCode = 500;
                }
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an Asp.Net 3.5 application and I need to print some application generated
I recently received some advice on a question regarding an easy to use web-framework
I need some sort of interactive chart control for my .NET-based web app. I
I had some very wrong sounding advice recently from a senior developer/coworker regarding the
I need some advice as to how I easily can separate test runs for
I need some expect advice on how to handle the following:- I have a
I need some info on how to use margins and how exactly padding works.
I need some help from the shell-script gurus out there. I have a .txt
I need some information about localization. I am using .net 2.0 with C# 2.0
I need some pointers on how to detect unknown hardware using .NET and C++/C#.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.