将参数从一个应用程序传递到另一个应用程序

时间:2014-03-21 11:19:51

标签: c# infopath

继续此帖子Starting application before target application

我有一个应用程序,它会传递一个参数(文件名)并在打开Microsoft InfoPath之前执行一些注册表工作。

我需要使用传递给原始应用程序的参数打开InfoPath。

以下是我打开InfoPath的方法

System.Diagnostics.Process prc = new System.Diagnostics.Process();
prc.StartInfo.Arguments = ConvertArrayToString(Constants.Arguments);
//prc.StartInfo.Arguments = "hello";
prc.StartInfo.FileName = Constants.PathToInfoPath;
prc.Start();

请注意,当我将Arguments设置为“hello”时,InfoPath弹出一条消息,说找不到文件“hello”但是当我设置它时Constants.Arguments我收到一个错误,Windows询问我是否要调试或关闭applicatiion。

以下是我在Constants.Arguments

中设置Main(string[] args)的方法
static void Main(string[] args)
{
    Constants.Arguments = args;
    //...
}

这里是ConvertArrayToString

private string ConvertArrayToString(string[] arr)
{

    string rtn = "";
    foreach (string s in arr)
    {
        rtn += s;
    }

    return rtn;

}

我想参数的格式是导致错误的,不知道为什么?

被串扰后Arguments的值是

c:\users\accountname\Desktop\HSE-000403.xml

编辑:

感谢N K的回答。

问题是为了在打开InfoPath文件时打开我的应用程序,我已将INFOPATH.EXE的名称更改为INFOPATH0.EXE,我的应用程序名为INFOPATH.EXE并且位于InfoPath文件夹中,因此当文件时打开我的应用程序。

现在当我不更改名称(例如我将其保留为INFOPATH.EXE)时,它按预期工作,但是如果它被调用以外的任何东西,那么我得到错误。

不幸的是我需要首先打开我的应用程序。

1 个答案:

答案 0 :(得分:1)

我尝试了以下,它的工作正常。让我知道你对此有何看法。 (不要忘记更改文件路径)

class Program
{
    static void Main(string[] args)
    {
        System.Diagnostics.Process prc = new System.Diagnostics.Process();
        prc.StartInfo.Arguments = string.Join("", Constants.Arguments);
        prc.StartInfo.FileName = Constants.PathToInfoPath;
        prc.Start();
    }
}
public class Constants
{
    public static string PathToInfoPath = @"C:\Program Files (x86)\Microsoft Office\Office14\INFOPATH.EXE";
    public static string[] Arguments = new string[] { @"c:\users\accountname\Desktop\HSE-000403.xml" };
}
相关问题