Exemplo n.º 1
0
 public void BuildDocument(string[] AutoTextName)
 {
     /* Here's where I look in the Glossary Document Part to determine it there IS AutoText
      * If there isn't, then there's no use in creating the List of AutoText objects!
      */
     gdp = sslmdp.GlossaryDocumentPart;
     if (gdp != null)
     {
         gd = gdp.GlossaryDocument;
         foreach (string atxname in AutoTextName)
         {
             atx = new CBAutoText(atxname, gd.DocParts, ssldoc.Body);
             atx.Insert();
         }
         wrddoc.SaveAs(DOC_PATH_NAME);
         wrddoc.Close();
     }
 }
Exemplo n.º 2
0
        public void BuildDocument(string[] AutoTextName)
        {
            /* Here's where I look in the Glossary Document Part to determine it there IS AutoText
             * If there isn't, then there's no use in creating the List of AutoText objects!
             */
            gdp = mdp.GlossaryDocumentPart;
            if (gdp != null)
            {
                foreach (string atxname in AutoTextName)
                {
                    atxt = new CBAutoText
                    {
                        GDP  = gdp,
                        Name = atxname
                    };
                    Console.WriteLine("AutoText Name ==> {0}", atxt.Name);

                    // Create a new relationship in the NEW document with the AutoText FOUND in the template
                    // Think about changing how this code is called.
                    atxt.CheckForRelationship();

                    // Retrieve RELATIONSHIP IDs from the document/document.xml in Main document/Document being created
                    Console.WriteLine("Count of Content Controls in this document is {0}\n", doc.Body.Descendants <SdtElement>().Count());
                    Console.ReadLine();

                    var cctrl = (from sdtCtrl in doc.Body.Descendants <SdtElement>()
                                 where sdtCtrl.SdtProperties.GetFirstChild <SdtAlias>().Val == atxt.CCName ||
                                 sdtCtrl.SdtProperties.GetFirstChild <SdtAlias>().Val == atxt.Name
                                 select sdtCtrl).SingleOrDefault();

                    XElement cc = XElement.Parse(atxt.CCContent);
                    IEnumerable <XAttribute> ccAttrs = cc.Descendants().Attributes();
                    var ccRelIDs = (from attrib in ccAttrs
                                    where attrib.Value.Contains("rId")
                                    select attrib).ToArray();

                    Console.WriteLine("List of IdPartPairs {0}", mdp.Parts.Count());
                    foreach (var item in mdp.Parts)
                    {
                        Console.WriteLine("RelIDs ==> {0}", item.RelationshipId);
                    }

                    Console.WriteLine("Found rIds {0}", ccRelIDs.Count());
                    foreach (var item in ccRelIDs)
                    {
                        Console.WriteLine("RelIDs ==> {0}", item);
                    }

                    Console.WriteLine();

                    if (ccRelIDs.Count() > 0)
                    {
                        foreach (var RelIDs in ccRelIDs)
                        {
                            oldid = RelIDs.Value;
                            Console.WriteLine("RelIDs = {0} and oldid = {1}", RelIDs.Value, oldid);
                        }
                    }


                    if (atxt.HasARelationship)
                    {
                        int i = 0;
                        foreach (var RelPart in atxt.RelationshipParts)
                        {
                            //Establish new relationship
                            atxt.NewRelID = mdp.CreateRelationshipToPart(RelPart);
                            newsignature  = atxt.Content.Replace(oldid, atxt.NewRelID);
                            i++;
                        }
                    }
                    if (newsignature.Length != 0)
                    {
                        cctrl.InnerXml = newsignature;
                    }
                    else
                    {
                        cctrl.InnerXml = atxt.Content;
                    }
                }
                wrddoc.SaveAs(DOC_PATH_NAME);
                wrddoc.Close();
            }
        }