【问题标题】:Get full path of text file or any file in c#在c#中获取文本文件或任何文件的完整路径
【发布时间】:2010-08-18 11:14:34
【问题描述】:

尊敬的先生,
我的问题是,当我打开我的 txt 文件时,即 abc.txt 所以我想在我的计算机中获得仅运行或打开文件的完整路径,我已经这样做了

Process prs=Process.GetProcessByName("notepad");
foreach(Process p in prs)
{
     p.Modules[0].FileName.ToString();
}

这给了我 Notepad.exe 路径。我想要我的文本文件路径,如 D:\abc.txt 所以我可以得到这个。

谢谢

【问题讨论】:

  • 您想在记事本中打开文件的路径吗?记事本不提供任何编程接口,因此没有简单的方法来检索它。

标签: c# templatetags


【解决方案1】:
string fullPath = Path.GetFullPath(strFileName);

【讨论】:

    【解决方案2】:

    您可以附加 FileSystemEventHandler 并检查打开或更改了哪些文件。

    也许这会有所帮助

    http://www.codeguru.com/csharp/csharp/cs_network/article.php/c6043

    【讨论】:

      【解决方案3】:

      对于记事本,您可以像这样获取文件名:

      Process[] prs = Process.GetProcessesByName("notepad");
      foreach (Process p in prs)
      {
          string title = p.MainWindowTitle;
          Console.WriteLine(title.Substring(0, title.IndexOf('-') -1));
      }
      

      重要的部分是:

      title.Substring(0, title.IndexOf('-') -1)
      

      很遗憾,这不会为您提供完整的路径。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-31
        • 2015-11-03
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多