如何使用代碼或指令碼啟用SharePoint的備用語言

來源:互聯網
上載者:User

標籤: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();
                }
            }
        }

    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.