如何使用代码或脚本启用SharePoint的备用语言
2014-06-29 10:58
295 查看
SP的多语言,需要安装语言包,然后手工去sharepoint下启动备用语言,如下图:【网站操作】-【语言设置】:
方法一:采用powershell处理
在很多项目情况下,需要用代码进行备用语言启动。采用powershell1、 编写如下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();
}
}
}
}
}
相关文章推荐
- 在游戏中如何使用LUA5.1脚本语言
- 【程序语言】C/C++中如何使用Lua脚本
- C代码中如何使用链接脚本中定义的变量
- 【程序语言】C/C++中如何使用Lua脚本
- unity 3d中如何创建公有共用的代码段或数据,让所有其他类或者脚本都能访问?(代码说明static 静态类的使用)
- 如何将PHP作为Shell脚本语言使用
- 如何在Java平台上使用脚本语言做Java开发
- 如何将PHP作为Shell脚本语言使用
- 如何将PHP作为Shell脚本语言使用
- [转]如何将PHP作为Shell脚本语言使用
- windows 下如何使用 Lua 语言绘制正弦函数图像?代码
- 如何实现无后台代码使用sharepoint本身自定义formfield。
- 如何在启用SharePoint浏览器功能的InfoPath 表单中添加托管代码以动态地加载并显示图片
- 启用SharePoint 的 web application下面所有站点“备用语言”
- 在C#开发中如何使用Client Object Model客户端代码获得SharePoint 网站、列表的权限情况
- 如何将PHP作为Shell脚本语言使用
- SharePoint2013与SharePoint2016语言切换原理以及如何使用代码进行语言切换
- awk 系列:如何使用 awk 语言编写脚本
- 在游戏中如何使用LUA脚本语言
- 如何在Java中使用Lua脚本语言