码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-06-29 19:42:51      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   get   使用   

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

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

bubuko.com,布布扣

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

bubuko.com,布布扣

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

bubuko.com,布布扣

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

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

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

bubuko.com,布布扣

提示:

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

    }
}

如何使用代码或脚本启用SharePoint的备用语言,布布扣,bubuko.com

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

标签:style   blog   http   color   get   使用   

原文地址:http://www.cnblogs.com/love007/p/3814876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!