Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
- adding fix for update namespace, using the tag instead of alias is …
Browse files Browse the repository at this point in the history
…more accurate for getting cc names
  • Loading branch information
desjarlais committed Aug 24, 2021
1 parent 617f145 commit bbd1e09
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 19 deletions.
37 changes: 24 additions & 13 deletions WinForms/FrmBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,7 @@ private void BtnUpdateQuickPartNamespaces_Click(object sender, EventArgs e)

if (xDoc.DocumentElement.NamespaceURI == StringResources.schemaMetadataProperties)
{
// loop through the metadata and get the uri's
foreach (XmlNode xNode in xDoc.ChildNodes)
{
if (xNode.Name == "p:properties")
Expand All @@ -1595,7 +1596,6 @@ private void BtnUpdateQuickPartNamespaces_Click(object sender, EventArgs e)
{
if (xNode2.Name == "documentManagement")
{

foreach (XmlNode xNode3 in xNode2.ChildNodes)
{
// add the node name and uri to a global list for comparing later
Expand All @@ -1615,29 +1615,38 @@ private void BtnUpdateQuickPartNamespaces_Click(object sender, EventArgs e)
// now that we know the namespaces, loop the controls and update their data binding prefix mappings
foreach (var cc in document.ContentControls())
{
string ccType = string.Empty;
string ccName = string.Empty;
SdtProperties props = cc.Elements<SdtProperties>().FirstOrDefault();

// get the data binding element
foreach (OpenXmlElement oxe in props.ChildElements)
{
// get the cc name from the tag
if (oxe.GetType().ToString() == "DocumentFormat.OpenXml.Wordprocessing.Tag")
{
foreach (OpenXmlAttribute oxa in oxe.GetAttributes())
{
ccName = oxa.Value;
}
}

// now use databinding to check the prefix mappings
if (oxe.GetType().ToString() == "DocumentFormat.OpenXml.Wordprocessing.DataBinding")
{
// create the DataBinding object
DataBinding db = (DataBinding)oxe;

// parse out the element name
string[] elemName = db.XPath.ToString().Split('/');

// parse out the xpath name and ns value to compare in the prefix mappings
string xPathName = elemName[elemName.Count() - 1];
//string nsValue = xPathName.Substring(0, 3);
string mappingName = xPathName.Substring(4, xPathName.Length - 7);

// check of the name is one of the managed metadata props
if (ccName == string.Empty)
{
// parse out the element name
string[] elemName = db.XPath.ToString().Split('/');
string xPathName = elemName[elemName.Count() - 1];
string mappingName = xPathName.Substring(4, xPathName.Length - 7);
}

// check if the content control prefix map name matches the metadata xml
foreach (string sName in nList)
{
if (sName == mappingName)
if (sName == ccName)
{
// parse out the namespace mapping but remove the space at the end first
string[] prefixMappingNamespaces = db.PrefixMappings.Value.TrimEnd().Split(' ');
Expand All @@ -1649,6 +1658,7 @@ private void BtnUpdateQuickPartNamespaces_Click(object sender, EventArgs e)
{
string xSubstring = "";

// the first mapping usually doesn't have xmlns at the beginning
if (s.StartsWith("xmlns:"))
{
xSubstring = s.Substring(11, s.Length - 11);
Expand All @@ -1661,6 +1671,7 @@ private void BtnUpdateQuickPartNamespaces_Click(object sender, EventArgs e)

if (xSubstring != nsList[nsIndex])
{
// add the xmlns to the guid
string valToReplace = "xmlns:ns" + nsIndex + "='" + nsList[nsIndex] + "'";
db.PrefixMappings.Value = db.PrefixMappings.Value.Replace(s, valToReplace);
fileChanged = true;
Expand Down
2 changes: 1 addition & 1 deletion bin/Debug/Office File Explorer.application
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>HuX3Cbkn44fuRtRqS8l8Ti0xlqOowWYhFRSqZVvQFB4=</dsig:DigestValue>
<dsig:DigestValue>7JB1FQwasifZ1M5PnUmOgQk614/1Ar49aJsxVktKt4Y=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified bin/Debug/Office File Explorer.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions bin/Debug/Office File Explorer.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Office File Explorer.exe" size="4517888">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Office File Explorer.exe" size="4518400">
<assemblyIdentity name="Office File Explorer" version="1.0.2.63" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>v+UpUQmd+w/KjIYNzg+fOMLx2OevFr1Pyuhwgj6U0c8=</dsig:DigestValue>
<dsig:DigestValue>467AM44sY2AaaEYdhmVAJjneEO1ChpRqB4RFUh0R5yQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified bin/Debug/Office File Explorer.pdb
Binary file not shown.
Binary file modified bin/Debug/app.publish/Office File Explorer.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/Office File Explorer.application
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>HuX3Cbkn44fuRtRqS8l8Ti0xlqOowWYhFRSqZVvQFB4=</dsig:DigestValue>
<dsig:DigestValue>7JB1FQwasifZ1M5PnUmOgQk614/1Ar49aJsxVktKt4Y=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified obj/Debug/Office File Explorer.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions obj/Debug/Office File Explorer.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Office File Explorer.exe" size="4517888">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Office File Explorer.exe" size="4518400">
<assemblyIdentity name="Office File Explorer" version="1.0.2.63" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>v+UpUQmd+w/KjIYNzg+fOMLx2OevFr1Pyuhwgj6U0c8=</dsig:DigestValue>
<dsig:DigestValue>467AM44sY2AaaEYdhmVAJjneEO1ChpRqB4RFUh0R5yQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified obj/Debug/Office File Explorer.pdb
Binary file not shown.

0 comments on commit bbd1e09

Please sign in to comment.