如何使用代码或脚本启用SharePoint的备用语言

SP的多语言,需要安装语言包,然后手工去sharepoint下启动备用语言,如下图:

【网站操作】-【语言设置】:

clip_image002

方法一:采用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盘根目录下)

clip_image002[4]

2、找到执行powershell的SP2010运行界面如下图:

clip_image003

以管理员身份运行,如下图:

clip_image004

clip_image006

clip_image008

1、 进入【语言设置】,查看备用语言已经启用,如下图:

clip_image010

提示:

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

    }
}
posted @ 2014-06-29 10:58  love007  阅读(411)  评论(0编辑  收藏  举报