Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / February 2006

Tip: Looking for answers? Try searching our database.

Late Bound Access to NormalTemplate.Saved property in Word (C#)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Evan Stone - 23 Feb 2006 23:22 GMT
Hi,

How would one go about accessing the Application.NormalTemplate.Saved
property in Word via C# and LATE bound?

I'm currently getting the infamous "do you want to save Normal.dot" error on
certain systems from the following code (it seems to be from fresh
installations of Word, since some default settings are being saved to
Normal.dot on the first run), and I'd like to be able to set the
NormalTemplate.Saved property to true to inhibit the dialog in that
situation...

   // Code Snippet Begin ----------------------
   Type WordType = Type.GetTypeFromProgID("Word.Application");

   //Create instance of word
   wordObject = Activator.CreateInstance(WordType);
   if (wordObject != null)
   {
       parameter[0] = true;

       //get the Version property
       version = (string) WordType.InvokeMember("Version",
           BindingFlags.DeclaredOnly | BindingFlags.Public |
BindingFlags.NonPublic |
           BindingFlags.Instance | BindingFlags.GetProperty, null,
wordObject, null);

       // close the application
       WordType.InvokeMember("Quit",
           BindingFlags.DeclaredOnly |
           BindingFlags.Public | BindingFlags.NonPublic |
           BindingFlags.Instance | BindingFlags.InvokeMethod, null,
wordObject, null);
   }
   wordObject = null;
   // Code Snippet End ----------------------

My question is how do I get at that property if I'm trying to work late
bound? Do I need to get the NormalTemplate object first then call an
InvokeMember on it to get the value of its Saved property?

Thanks!

evan k. stone | software engineer
----------------------------------------
santa rosa, ca, usa
Tony Jollans - 24 Feb 2006 13:23 GMT
I don't know C#, but late binding shouldn't make a difference to how you
access the property (it may affect things behind the scenes but not the
source code needed).

--
Enjoy,
Tony

> Hi,
>
[quoted text clipped - 43 lines]
> ----------------------------------------
> santa rosa, ca, usa
Cindy M  -WordMVP- - 25 Feb 2006 15:52 GMT
Hi Evan,

> How would one go about accessing the Application.NormalTemplate.Saved
> property in Word via C# and LATE bound?

Something like this works for me:

   wd.ApplicationClass wdApp;
   //Assign it to an Word application; not shown here
   //Variable to which value will be assigned
   bool NT_Saved = true;

   //Test with early binding in order to compare result
   //Remove later               
MessageBox.Show(wdApp.NormalTemplate.Saved.ToString());

   try
   {
    //You'll have already done this...
       Type wdApp_Type = wdApp.GetType();
    object NT = wdApp_Type.InvokeMember("NormalTemplate",
BindingFlags.GetProperty, null, wdApp, null);
    Type NT_Type = NT.GetType();
    NT_Saved = (bool) NT_Type.InvokeMember("Saved",
        BindingFlags.Default |
        BindingFlags.GetProperty,
        null, NT, null );
   }
   catch (System.Exception ex)
   {
    MessageBox.Show(ex.ToString());
   }
//Show the result of late-binding
   MessageBox.Show(NT_Saved.ToString());

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.