C# 正在尝试将文件名从aspx页传递到console.exe

C# 正在尝试将文件名从aspx页传递到console.exe,c#,textbox,console,argument-passing,C#,Textbox,Console,Argument Passing,我想将aspx页面中标签或文本框的值传递给console.exe应用程序 这样,如果值为sample.doc,则会更改为sample.doc 我从aspx页面打电话给 string f = TextBox1.Text; System.Diagnostics.Process.Start("C:/DocUpload/ConsoleApplication1.exe", f); 我尝试转换为字符串,然后使用字符串vatiable替换sample.doc,但没有成功 对象文件名=Syst

我想将aspx页面中标签或文本框的值传递给console.exe应用程序 这样,如果值为sample.doc,则会更改为sample.doc

我从aspx页面打电话给

   string f = TextBox1.Text;

    System.Diagnostics.Process.Start("C:/DocUpload/ConsoleApplication1.exe", f);
我尝试转换为字符串,然后使用字符串vatiable替换sample.doc,但没有成功

对象文件名=System.IO.Path.Combine(ExecutableFileInfo.DirectoryName,“sample.doc”)

任何帮助或想法都将受到欢迎。
谢谢你

以下是我用来启动调用应用程序的流程的方法。由于您是从web应用程序调用它,因此需要确保您具有适当的权限

        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();
processproc=newprocess();
StringBuilder sb=新的StringBuilder();
字符串[]atatarget=target.Split(路径分隔符);
字符串错误消息;
字符串输出消息;
foreach(参数中的字符串参数)
{
sb.追加(parm+“”);
}
proc.StartInfo.FileName=目标;
proc.StartInfo.RedirectStandardError=true;
proc.StartInfo.RedirectStandardOutput=true;
proc.StartInfo.UseShellExecute=false;
proc.StartInfo.Arguments=sb.ToString();
proc.Start();
WaitForExit程序
(

(超时您可能正在尝试处理另一个文件夹中的文件

如果是这样,您需要传递文件的完整路径,如下所示:

Process.Start(@"C:\DocUpload\ConsoleApplication1.exe", 
              Path.Combine(@"C:\path\to\folder", TextBox1.Text));

textbox的值是什么?它应该是磁盘上的文件吗?如果是,是哪个文件夹?出现了什么错误?你应该命名你的textbox。textbox的值是我要处理的文件的名称,控制台应用程序启动的任何时间点都会显示文件名并崩溃链接到MSDN时,你应该链接到默认版本,而不是.Net 1.1。嘿,伙计们,谢谢你们的建议,它让我思考得更多,所以我在aspx文件字符串filename=TextBox1.Text;System.Diagnostics.Process.Start(“C:/DocUpload/ConsoleApplication1.exe”,filename)中使用了这个,并在console.exe StringBuilder sb=new StringBuilder();foreach上使用了下面的代码(args中的字符串s){sb.Append(s);}object docFileName=System.IO.Path.Combine(ExecutableFileInfo.DirectoryName,sb.ToString());非常感谢大家,console应用程序和文件位于同一文件夹中,但将尝试您的建议