標籤:style blog http color get 使用
SP的多語言,需要安裝語言套件,然後手工去sharepoint下啟動備用語言,如:
【網站操作】-【語言設定】:
方法一:採用powershell處理
在很多項目情況下,需要用代碼進行備用語言啟動。採用powershell
1、 編寫如下powershell指令碼,如下:
#################################################################################
########################## Change Inputs Below ##################################
#################################################################################
# Cycles through all site collections and subsites to turn on all installed
# languages. Run per web app. Goes multiple levels deep.
$WebAppURL = "http://win-i07fillcfom:8004"
#################################################################################
########################## Code, No Changes Below ###############################
#################################################################################
clear
$PSSnapin = Remove-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
$PSSnapin = Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
$WebApp = Get-SPWebApplication $WebAppURL
Foreach ($SiteColl in $WebApp.Sites)
{
$rootSite = Get-SPSite $SiteColl.Url
$allWebs = $rootSite.AllWebs
foreach ($web in $allWebs)
{
Write-Host "Updating" + $web.Title + "" + $web.Url
if ($web.IsMultilingual -eq $false)
{ $web.IsMultilingual = $true; }
$WebRegionSettings = New-Object Microsoft.SharePoint.SPRegionalSettings($web)
Foreach ($lang in $WebRegionSettings.InstalledLanguages)
{
If ($web.SupportedUICultures -notcontains $lang.LCID)
{ $web.AddSupportedUICulture($lang.LCID) }
}
$web.Update()
$web.Close()
$web.Dispose()
}
}
並把指令碼儲存成.ps1檔案(注意:修改好webAPPUrl),我這裡儲存為:EnableAltLang2.ps1(儲存到有SP2010的伺服器E盤根目錄下)
2、找到執行powershell的SP2010運行介面如:
以管理員身份運行,如:
1、 進入【語言設定】,查看備用語言已經啟用,如:
提示:
1、 如果想使用定時自動啟動,可以結合windows計劃任務
方法二:採用SDK的API
代碼部分:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System.Collections;
namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://win-i07fillcfom:8004"))
{
using (SPWeb web = site.OpenWeb(""))
{
web.IsMultilingual = true;
// Add support for any installed language currently not supported.
SPLanguageCollection installed = SPRegionalSettings.GlobalInstalledLanguages;
IEnumerable supported = web.SupportedUICultures;
foreach (SPLanguage language in installed)
{
CultureInfo culture = new CultureInfo(language.LCID);
web.AddSupportedUICulture(culture);
}
web.Update();
Console.WriteLine("ok");
Console.Read();
}
}
}
}
}