开发者

trying to pass file name from aspx page to console.exe

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 t开发者_StackOverflowo 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


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));


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜