Click here to Skip to main content
15,914,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: blackberry Pin
Heath Stewart22-Feb-05 12:05
protectorHeath Stewart22-Feb-05 12:05 
GeneralRe: blackberry Pin
2new24-Feb-05 9:00
2new24-Feb-05 9:00 
QuestionHow to make TreeView like navigation bar Pin
lee meng22-Feb-05 2:58
lee meng22-Feb-05 2:58 
Generalformatting number Pin
dhol22-Feb-05 1:56
dhol22-Feb-05 1:56 
GeneralRe: formatting number Pin
leppie22-Feb-05 5:38
leppie22-Feb-05 5:38 
GeneralRe: formatting number Pin
dhol22-Feb-05 16:38
dhol22-Feb-05 16:38 
GeneralGetting the path of an open Word document Pin
Paladin5522-Feb-05 1:41
Paladin5522-Feb-05 1:41 
GeneralRe: Getting the path of an open Word document Pin
Heath Stewart22-Feb-05 12:30
protectorHeath Stewart22-Feb-05 12:30 
Are you saying you want to get the open document itself, or just the path? Keep in mind that Word can have many documents open. You need to get the Word.Application instance from the Running Object Table (ROT). To do that you pass "Word.Application" to System.Runtime.InteropServices.Marshal.GetActiveObject and cast to the ApplicationClass in the Word PIA (Primary Interop Assemblies; these are installed with a development feature of Office 2003 Professional and downloadable for Office XP from http://msdn.microsoft.com[^]. They can also be generated automatically.). Once you've done that you can easily get the active document:
using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Word;
 
class ActiveDoc
{
  const string WordProgId = "Word.Application";
 
  static void Main()
  {
    ApplicationClass app = Marshal.GetActiveObject(WordProgId)
      as ApplicationClass;
    if (app != null)
    {
      try
      {
        DocumentClass doc = (DocumentClass)app.ActiveDocument;
        if (doc != null)
          Console.WriteLine(doc.Path);
      }
      catch (COMException)
      {
        Console.Error.WriteLine("No document is open.");
      }
    }
    else
      Console.Error.WriteLine("Word is not running.");
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralWeb method's parameter Pin
Ed Lee22-Feb-05 1:05
Ed Lee22-Feb-05 1:05 
GeneralRe: Web method's parameter Pin
J4amieC22-Feb-05 1:43
J4amieC22-Feb-05 1:43 
GeneralRe: Web method's parameter Pin
Anonymous22-Feb-05 13:55
Anonymous22-Feb-05 13:55 
GeneralRe: Web method's parameter Pin
J4amieC22-Feb-05 23:30
J4amieC22-Feb-05 23:30 
GeneralUTF8 Encoding - need help or explanation Pin
Radoslav Bielik21-Feb-05 23:56
Radoslav Bielik21-Feb-05 23:56 
GeneralRe: UTF8 Encoding - need help or explanation Pin
Mike Dimmick22-Feb-05 2:21
Mike Dimmick22-Feb-05 2:21 
GeneralRe: UTF8 Encoding - need help or explanation Pin
Radoslav Bielik22-Feb-05 5:08
Radoslav Bielik22-Feb-05 5:08 
GeneralMouse position Pin
The underdog21-Feb-05 23:08
The underdog21-Feb-05 23:08 
GeneralRe: Mouse position Pin
Stefan Troschuetz22-Feb-05 1:45
Stefan Troschuetz22-Feb-05 1:45 
GeneralSending SMS Pin
innocent7321-Feb-05 22:50
innocent7321-Feb-05 22:50 
GeneralSpecialised task manager Pin
clatten21-Feb-05 21:39
clatten21-Feb-05 21:39 
GeneralRe: Specialised task manager Pin
Heath Stewart22-Feb-05 8:22
protectorHeath Stewart22-Feb-05 8:22 
GeneralRe: Specialised task manager Pin
clatten22-Feb-05 12:45
clatten22-Feb-05 12:45 
GeneralRe: Specialised task manager Pin
Heath Stewart22-Feb-05 13:04
protectorHeath Stewart22-Feb-05 13:04 
GeneralRe: Specialised task manager Pin
clatten23-Feb-05 20:55
clatten23-Feb-05 20:55 
GeneralAddress Book Pin
jstrulens21-Feb-05 21:08
jstrulens21-Feb-05 21:08 
GeneralRe: Address Book Pin
sharathgowda21-Feb-05 21:43
sharathgowda21-Feb-05 21:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.