我想在Sharepoint web.config文件中的appSetting中添加两个键值。
我找到了一个使用以下链接
修改blobcache属性的好例子以及我可以添加新密钥的链接。
http://farhanfaiz.wordpress.com/2011/09/07/sharepoint-2010-powershell-script-to-add-in-web-config/
这是我在Appsetting中添加两个键的代码。
function AddAppSettingKey {
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]
$WebApplication
)
process {
Write-Host "Modification starts..." -ForegroundColor Green
$WebApp = $WebApplication.Read()
Write-Host $WebApp
$configMod1 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$configMod1.Path = "configuration/appSettings"
$configMod1.Name = "add[@name='key']"
$configMod1.Value = "<add key= 'RedirectToPage' value='Main.aspx' />"
$configMod1.Sequence = 0
$configMod1.Type = 1
$configMod1.Owner = "AppSettingMod"
$configMod2 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$configMod2.Path = "configuration/appSettings"
$configMod2.Name = "add[@name='key']"
$configMod2.Value = "<add key= 'isProd' value='false' />"
$configMod2.Sequence = 0
$configMod2.Type = 1
$configMod2.Owner = "AppSettingMod"
$WebApp.WebConfigModifications.Add($configMod1)
$WebApp.WebConfigModifications.Add($configMod2)
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()
Write-Host "Done......" -ForegroundColor Cyan
}
}
但我的问题是当我执行代码时,我得到以下错误:
Exception calling "ApplyWebConfigModifications" with "0" argument(s): "'/' is a
n unexpected token.
任何输入都会非常有用。
答案 0 :(得分:0)
我认为“.Type = 1
”是SPWebConfigModificationType.EnsureAttribute
,而我应该使用SPWebConfigModificationType.EnsureChildNode(0)
。
更改为“.Type = 0
”并重试。