private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { //prompt to delete the stream if (ShowYesNoMessage(Properties.Resources.DeletePartMessage) == DialogResult.Yes) { try { //try to delete the stream Office.CustomXMLPart partToDelete = CurrentPartCollection[m_intLastSelected + 1]; partToDelete.Delete(); //refresh the picker RefreshPartList(true, true, false, string.Empty, null, null); //set the new selection m_intLastSelected = comboBoxPartList.SelectedIndex; //fire back at the event class to switch up the event handlers as well Debug.Assert(EventHandler != null, "null event handler"); EventHandler.ChangeCurrentPart(CurrentPartCollection[m_intLastSelected + 1]); } catch (COMException ex) { ShowErrorMessage(string.Format(CultureInfo.CurrentUICulture, Properties.Resources.ErrorDeletePart, ex.Message)); } } }
/// <summary> /// remove custom xml part (internal bookmark, osql, checksum, comment) /// </summary> /// <param name="wDoc"></param> private void RemoveCustomXmlParts(Microsoft.Office.Interop.Word.Document wDoc) { try { Pdwx.Services.WordHeper.RemoveProtectPassword(wDoc, ProtectLevel.All); // accept all changes try { if (wDoc.TrackRevisions) { wDoc.AcceptAllRevisions(); } } catch { } List <string> xmlPartIds = new List <string>(); if (wDoc.CustomXMLParts != null) { foreach (Microsoft.Office.Core.CustomXMLPart xmlPart in wDoc.CustomXMLParts) { if (!xmlPart.BuiltIn) { xmlPartIds.Add(xmlPart.Id); } } } foreach (string xmlPartId in xmlPartIds) { Microsoft.Office.Core.CustomXMLPart oldXmlPart = wDoc.CustomXMLParts.SelectByID(xmlPartId); if (oldXmlPart != null) { oldXmlPart.Delete(); } } if (wDoc.Bookmarks != null) { foreach (Microsoft.Office.Interop.Word.Bookmark wBm in wDoc.Bookmarks) { if (Core.MarkupUtilities.IsProntoDocCommentBookmark(wBm.Name)) { wBm.Range.Text = string.Empty; // remove the bookmark } } } } catch { } }
private void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e) { Office.CustomXMLPart docDataSetPart = null; // Belgedeki içerik kontrol kutularıyla ilgili bilgileri içeren // veri setini belgeye ait XML alanları arasında sakla. if (docDataSetID != null) { docDataSetPart = this.CustomXMLParts.SelectByID(docDataSetID); if (docDataSetPart != null) { docDataSetPart.Delete(); } } string xmlDataSet = docDataSet.GetXml(); docDataSetPart = this.CustomXMLParts.Add(xmlDataSet); Office.DocumentProperties docProps = this.CustomDocumentProperties as Office.DocumentProperties; if (docDataSetID != null) { docDataSetID = docDataSetPart.Id; foreach (Office.DocumentProperty docprop in docProps) { if (docprop.Name == "HurTestDataSet") { docprop.Value = docDataSetID; break; } } } else { docDataSetID = docDataSetPart.Id; docProps.Add("HurTestDataSet", false, Office.MsoDocProperties.msoPropertyTypeString, docDataSetID, missing); } }
public void toggleButtonMapping_Click(Office.IRibbonControl control, bool pressed)//, ref bool cancelDefault) { Word.Document document = Globals.ThisAddIn.Application.ActiveDocument; //get the ctp for this window (or null if there's not one) CustomTaskPane ctpPaneForThisWindow = Utilities.FindTaskPaneForCurrentWindow(); if (pressed) { toggleButtonMappingChecked = true; } if (toggleButtonMappingChecked == false) { //Debug.Assert(ctpPaneForThisWindow != null, // "how was the ribbon button pressed if there was a control?"); //it's being unclicked if (ctpPaneForThisWindow != null) { ctpPaneForThisWindow.Visible = false; } } else if (ctpPaneForThisWindow == null) { if (CustomXmlUtilities.areOpenDoPEPartsPresent(Globals.ThisAddIn.Application.ActiveDocument)) { log.Debug("OpenDoPE parts detected as present"); } else { log.Info("OpenDoPE parts not detected; adding now."); Model model = Model.ModelFactory(document); string requiredRoot = System.Configuration.ConfigurationManager.AppSettings["RootElement"]; Office.CustomXMLPart userPart = model.getUserPart(requiredRoot); bool cancelled = false; while (userPart == null && !cancelled) { using (Forms.FormAddPart fap = new Forms.FormAddPart()) { //add a new stream from the XML retrieved from the Add New dialog //otherwise, select the last selected item and populate with its xml if (fap.ShowDialog() == DialogResult.OK) { object missing = System.Reflection.Missing.Value; Office.CustomXMLPart newCxp = document.CustomXMLParts.Add(fap.XmlString, missing); model = Model.ModelFactory(document); userPart = model.getUserPart(requiredRoot); if (userPart == null) { newCxp.Delete(); MessageBox.Show("You need to use root element: " + requiredRoot); } } else { cancelled = true; } } } if (cancelled) { MessageBox.Show("For template authoring, you need to add your XML."); toggleButtonMappingChecked = false; return; } InitialSetup init = new InitialSetup(); init.process(); } launchTaskPane(); } else { //it's built and being clicked, show it ctpPaneForThisWindow.Visible = true; } }