簡體   English   中英

C#-如何使用參數使用Word打開文檔

[英]C# - How to open a doc with word using arguments

我想讓我的程序打開word,然后打開一個特定的文檔,實際上只是以word為例。 這在其他情況下可能很有用,但是我想知道如何使用參數。 我有一些代碼可以打開程序,還有一些代碼可以在文件路徑不存在的情況下顯示錯誤消息:

    private void StartProcess(string path)
    {
        ProcessStartInfo StartInformation = new ProcessStartInfo();

        StartInformation.FileName = path;

        Process process = Process.Start(StartInformation);

        process.EnableRaisingEvents = true;
    }
    private void ClickFunc(object sender, RoutedEventArgs e)
    {
        if (File.Exists(ProgramPath))
        {
            StartProcess(ProgramPath);
        }
        else
        {
            MessageBox.Show("Specified path does not exist, please try again.", "Bad File Path Error", MessageBoxButton.OK);
        }
    }

我想知道如何添加參數。 謝謝!

您可以使用ProcessStartInfo類的Arguments屬性添加命令行參數。

像這樣:

 ProcessStartInfo startInfo = new ProcessStartInfo("winword");
 startInfo.Arguments = "/a /b";

您也可以在ProcessStartInfo構造函數中將命令行參數指定為字符串。

從MSDN檢查此鏈接

https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.arguments(v=vs.110).aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM