InfoPath问题 [英] InfoPath issues
问题描述
Hello Techies,
I need to update the xml of InfoPath using powershell.
需要更新以下3个节点的内部文本:
Need to update the innertext of below 3 nodes :
< my:URL1> HTTP ://SHAREPOINT/sp/abc/DocLib/FR/PCDAMON%2021-529574/2014 </my:URL1Read>
< my:BaseDocFolder> HTTP://SHAREPOINT/sp/abc/DocLib/FR </my:BaseDocFolder>
<my:URL1>HTTP://SHAREPOINT/sp/abc/DocLib/FR/PCDAMON%2021-529574/2014</my:URL1>
<my:URL1Read>HTTP://SHAREPOINT/sp/abc/DocLib/FR/PCDAMON%2021-529574/2014</my:URL1Read>
<my:BaseDocFolder>HTTP://SHAREPOINT/sp/abc/DocLib/FR</my:BaseDocFolder>
要实现这一点,我尝试了以下步骤:
To accomplish this.. i tried below steps:
- 我可以使用以下脚本在表单中更改网址:
- I mapped the infopath library on to my local system so that i can run my script on all the forms.
- I was able to change the urls within the form using the below script:
$files = Get-ChildItem Z:\ #-recurse #| Format-Table FullName
foreach ($file in $files)
{
$path = $file.FullName
#Write-Host "Path:"$path
[xml]$xml = Get-Content $path
$url1 = $xml.myFields.FileAttachments.URL1
$url1Read = $xml.myFields.FileAttachments.URL1Read
$url2 = $xml.myFields.FileAttachments.URL2
$url2Read = $xml.myFields.FileAttachments.URL2Read
$url3 = $xml.myFields.FileAttachments.URL3
$url3Read = $xml.myFields.FileAttachments.URL3Read
$baseDocFolder = $xml.myFields.FileAttachments.BaseDocFolder
$saveForm = "false"
Write-Host "Path:"$path
if ($url1 -and $url1 -Match "HTTP://oldSPURL/")
{
Write-Host "URL1"$url1
$url1=$url1.replace("HTTP://oldSPURL/","http://newSPURL/")
Write-Host "NewURL1"$url1
$xml.myFields.FileAttachments.URL1=$url1
$saveForm="true"
}
if ($url1Read -and $url1Read -Match "HTTP://oldSPURL/")
{
Write-Host "URL1"$url1Read
$url1Read=$url1Read.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "NewURL1"$url1
$xml.myFields.FileAttachments.URL1Read=$url1Read
$saveForm="true"
}
if ($url2 -and $url2 -Match "HTTP://oldSPURL/")
{
Write-Host "URL2"$url2
$url2=$url2.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "NewURL2"$url2
$xml.myFields.FileAttachments.URL2=$url2
$saveForm="true"
}
if ($url2Read -and $url2Read -Match "HTTP://oldSPURL/")
{
Write-Host "URL1"$url2Read
$url2Read=$url2Read.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "NewURL1"$url2Read
$xml.myFields.FileAttachments.URL2Read=$url2Read
$saveForm="true"
}
if ($url3 -and $url3 -Match "HTTP://oldSPURL/")
{
Write-Host "URL3"$url3
$url3=$url3.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "NewURL3"$url3
$xml.myFields.FileAttachments.URL3=$url3
$saveForm="true"
}
if ($url3Read -and $url3Read -Match "HTTP://oldSPURL/")
{
Write-Host "URL1"$url3Read
$url3Read=$url3Read.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "NewURL1"$url2Read
$xml.myFields.FileAttachments.URL3Read=$url3Read
$saveForm="true"
}
if ($baseDocFolder -and $baseDocFolder -Match "HTTP://oldSPURL/")
{
Write-Host "baseDocFolder"$baseDocFolder
$baseDocFolder=$baseDocFolder.replace("HTTP://oldSPURL/","HTTP://newSPURL/")
Write-Host "baseDocFolderURL"$baseDocFolder
$xml.myFields.FileAttachments.BaseDocFolder=$baseDocFolder
$saveForm="true"
}
if($saveForm -eq "true")
{
$xml.Save($path)
Write-Host "Form has been updated"
}
}
But while accesing the forms from the browser, it displays one of the below errors for almost all the 200 forms.
推荐答案
作为一种解决方法,我们可以通过C#代码实现.
As a workaround, we can achieve it by C# code.
这里是一个有关如何使用C#编辑xml文件的演示,供您参考.
Here is a demo about how to edit xml file with C# for your reference.
static void Main(string[] args)
{
string siteURL = "http://sp/sites/DevSite";
SPSite spSite = new SPSite(siteURL);
SPList myList = spSite.RootWeb.Lists["myList"];
SPListItem item = myList.GetItemById(123);
XmlDocument xmlItem = new XmlDocument();
//Open XML file and load it into XML document
using (Stream streamItem = item.File.OpenBinaryStream())
{
xmlItem.Load(streamItem);
}
XPathNavigator navItem = xmlItem.CreateNavigator();
//Redefine NameSpaceManager (Generate the NameSpace manager for this item)
navItem.MoveToFollowing(XPathNodeType.Element);
XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());
foreach (var ns in navItem.GetNamespacesInScope(XmlNamespaceScope.All))
{
if (ns.Key == String.Empty)
{
nsManager.AddNamespace("def", ns.Value);
}
else
{
nsManager.AddNamespace(ns.Key, ns.Value);
}
}
//Change your value here….
navItem.SelectSingleNode("/my:myFields/my:yourFieldName", nsManager);
//Save the modified xml into the item
byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(navItem.OuterXml);
item.File.SaveBinary(xmlData);
item.File.Update();
}
}
最诚挚的问候,
刘李
这篇关于InfoPath问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!