zoukankan      html  css  js  c++  java
  • 如何使用代码或脚本启用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();
    
                    }
    
                }
    
            }
    
    
    
        }
    
    }
    
  • 相关阅读:
    ios 属性的特性
    ios 线程锁 与 线程交互
    iOS 变量名前为什么要加_下划线
    ios 常见问题
    ios 沙盒
    ios 去掉屏幕键盘的方法
    UITableView方法详解
    Image View、Text Field、Keyboard 隐藏键盘
    用php 进行对文件的操作 (上)
    文件上传-------头像上传预览
  • 原文地址:https://www.cnblogs.com/love007/p/3814876.html
Copyright © 2011-2022 走看看