Esempio n. 1
0
        /// <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 { }
        }