C# 获取当前运行c的docx的路径和名称#

C# 获取当前运行c的docx的路径和名称#,c#,ms-word,vsto,add-in,docx,C#,Ms Word,Vsto,Add In,Docx,我正在为word编写一个外接程序,在下面的代码中,我获取文件中的所有单词并将它们放入字典中 ` Dictionary<string, string> motRap = new Dictionary<string, string>(); Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application(); Docume

我正在为word编写一个外接程序,在下面的代码中,我获取文件中的所有单词并将它们放入字典中

`
   Dictionary<string, string> motRap = new Dictionary<string, string>();
   Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
   Document document = application.Documents.Open("monfichiertxt.docx");

        // Loop through all words in the document.
        int count = document.Words.Count;
        for (int i = 1; i <= count; i++)
        {
            // Write the word.
            string text = document.Words[i].Text;
            //motRapport.Add(text);
            motRap.Add(text, "blabla");
        }
        // Close word.
        application.Quit();
`
Dictionary motRap=新字典();
Microsoft.Office.Interop.Word.Application Application=新的Microsoft.Office.Interop.Word.Application();
Document=application.Documents.Open(“monfichiertxt.docx”);
//循环浏览文档中的所有单词。
int count=document.Words.count;

对于(int i=1;i这个问题以前已经处理过,而且从未尝试过,1个谷歌,2行代码,我得到了一个简单的答案。虽然作为一个插件,我没想到你需要这样做才能得到你已经参与的单词实例

    Microsoft.Office.Interop.Word.Application word = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;
    label1.Text = word.ActiveDocument.Name;
您可以使用属性或类似于此的属性

string name = document.Name;
string fullName = document.FullName;

Name将为您提供“MyDocument.docx”,FullName将为您提供“…\MyFolder\MyDocument.docx”

您必须知道,我们没有所有的能力像您那样轻松地找到问题的答案。谢谢您的回答,但这对我的情况不起作用。谢谢您,这正是我想要的