views:

64

answers:

2

i want to pass the value of a lable or textbox in an aspx page to a console.exe application such that the if the value is sample.doc it changes to that.

i am calling from the aspx page with

   string f = TextBox1.Text;

    System.Diagnostics.Process.Start("C:/DocUpload/ConsoleApplication1.exe", f);

i have tried converting to string then using the string vatiable inplace of sample.doc but no luck

object FileName = System.IO.Path.Combine(ExecutableFileInfo.DirectoryName, "sample.doc");

any help or ideas will be welcomed. thank u

A: 

Here is what I use to start processes from calling applications. Since you are calling it from a web-app you are going to need to make sure you have appropriate permissions.

        Process         proc                = new Process();
        StringBuilder   sb                  = new StringBuilder();
        string[]        aTarget             = target.Split(PATH_SEPERATOR); 
        string          errorMessage;
        string          outputMessage;

        foreach (string parm in parameters)
        {
            sb.Append(parm + " ");
        }

        proc.StartInfo.FileName                 = target;
        proc.StartInfo.RedirectStandardError    = true;
        proc.StartInfo.RedirectStandardOutput   = true;
        proc.StartInfo.UseShellExecute          = false;
        proc.StartInfo.Arguments                = sb.ToString();

        proc.Start();

        proc.WaitForExit
            (
                (timeout <= 0)
                ? int.MaxValue : (int)TimeSpan.FromMinutes(timeout).TotalMilliseconds
            );


        errorMessage    = proc.StandardError.ReadToEnd();
        proc.WaitForExit();

        outputMessage   = proc.StandardOutput.ReadToEnd();
        proc.WaitForExit();

A link to MSDN:

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

You'll also need to check to make sure that the account the Web application is running under has the appropriate permissions to execute the program.

Kevin
When linking to MSDN, you should link to the default version, not .Net 1.1.
SLaks
hey Guys thanks for the suggsetions it got me thinking more so i used this in the aspx file string filename = TextBox1.Text; System.Diagnostics.Process.Start("C:/DocUpload/ConsoleApplication1.exe", filename)and used the code below on the console.exeStringBuilder sb = new StringBuilder(); foreach (string s in args) { sb.Append(s); }object docFileName = System.IO.Path.Combine(ExecutableFileInfo.DirectoryName, sb.ToString());thanks alot guys ur the best
ryder1211212
A: 

You're probably trying to process a file that is in a different folder.

If so, you need to pass the full path of the file, like this:

Process.Start(@"C:\DocUpload\ConsoleApplication1.exe", 
              Path.Combine(@"C:\path\to\folder", TextBox1.Text));
SLaks
well the console app and the files are in the same folder but will try your recommendation
ryder1211212