/// <summary> /// set the confidential level /// </summary> /// <param name="sensitive"> confidential level string</param> private void SetWorkbookSensitive(string sensitive) { try { Microsoft.Office.Core.DocumentProperties prp = Globals.ThisAddIn.Application.ActiveDocument.CustomDocumentProperties; bool isSenitive = false; foreach (Microsoft.Office.Core.DocumentProperty documentProperty in prp) { if (documentProperty.Name.Equals("Sensitive")) { //MessageBox.Show(documentProperty.Value); //InitRabbionControl(documentProperty.Value); documentProperty.Value = sensitive; isSenitive = true; } } if (isSenitive == false) { prp.Add("Sensitive", false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, sensitive, null); } Globals.ThisAddIn.InitRabbionControl(sensitive); } catch (Exception) { throw; } }
void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel) { Microsoft.Office.Interop.Word.Document nativeDocument = Globals.ThisAddIn.Application.ActiveDocument; Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(nativeDocument); Microsoft.Office.Core.DocumentProperties properties = (Office.DocumentProperties)vstoDocument.CustomDocumentProperties; string messageBoxText = "We noticed you haven't classified your document, would you like to opt out of classifying this document?"; string caption = "Classify Your Document"; object oBasic = Application.WordBasic; object fIsAutoSave = oBasic.GetType().InvokeMember( "IsAutosaveEvent", BindingFlags.GetProperty, null, oBasic, null); MessageBoxButtons button = MessageBoxButtons.YesNo; MessageBoxIcon icon = MessageBoxIcon.Warning; if (ReadDocumentProperty2("Classification") == null && !(int.Parse(fIsAutoSave.ToString()) == 1)) { DialogResult result = MessageBox.Show(messageBoxText, caption, button, icon); switch (result) { case DialogResult.Yes: properties.Add("Classification", false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, "Not Classified"); break; case DialogResult.No: MessageBox.Show("Please add a classification and try saving the document again", "Classify", MessageBoxButtons.OK, MessageBoxIcon.Information); Cancel = true; break; } } }