简体   繁体   中英

c#.net Word add-in

I am developing an add-in in C#.net for Office-2013 , that shows a pop up message whenever user tries to export or share the document. I have seen word PIA has the DocumentBeforeSaveEvent but no such event for share and export .

Thus my query is can I make my own events to be used with the Word add-in which shows pop up if user tries to share or export the document.

If yes, what would be the possible step to do so?

The basic purpose of the add-in is to act as RMS(Right Management System), such that if user tries to save a document that is not protected as per restrict access' templates, then it should automatically attach the default template to the document before user saves it. The object model of Word, is of not much help either, thus would like to know what should be the process to develop such an add-in using C#.net for Office-2013

You can do this by overwriting the appropriate commands in your Ribbon XML.

You need to add a <commands> node to the XML and include subelements for the relevant Word commands as follows:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
   onLoad="OnLoad" > 
   <commands> 
     <command idMso="FileSave" onAction="mySave" /> 
   </commands> 
   <ribbon startFromScratch="false"> 
     <tabs> 
       <tab id="tab1" label="Repurpose Command Demo" > 
         <group id="group1" label="Demo Group"> 
           <toggleButton id="togglebutton1"  
             imageMso="AcceptInvitation"  
             size="large"  
             label="Alter Built-ins"  
             onAction="changeRepurpose" /> 
         </group> 
       </tab> 
     </tabs> 
   </ribbon> 
</customUI>

You then have to add a corresponding callback that gets executes whenever the user tries to execute the command in question:

public void mySave(IRibbonControl control, bool cancelDefault)
{
    If (repurposing)
    {
        MessageBox.Show("The Save button has been temporarily repurposed.");
        cancelDefault = False;
    }
    else
    {
        cancelDefault = False;
    }
}

MSDN has a full sample here: Temporarily Repurpose Commands on the Office Fluent Ribbon

In your case the command ids are probably FileSaveAsPdfOrXps and ShareWithPeople (or similar). You can find an Excel document containing all Office Ribbon ids here: idMso Tables .

Update

After your edit to the original question it looks like you may want to setup an RMS server for Office and define appropriate Rights Policy Templates . To get you started you can read up on this topic here: Plan Information Rights Management in Office 2013

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM