[英]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檢查此鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.