• 怎样用C#代码管理SharePoint解决方式


    怎样用C#代码管理SharePoint解决方式

            本文我们将了解怎样用代码管理SharePoint解决方式。我们使用server端对象模型抽取解决方式。
            SharePoint中解决方式有两类:沙盒解决方式和场解决方式。 沙盒解决方式和场解决方式使用不同方式部署,而且通过不同对象模型抽取。
            注意:这里用SPUserSolution代表沙盒解决方式;SPFarmSolution代表场解决方式。

    怎样获得沙盒解决方式

            沙盒解决方式在站点集层次部署。以下是在站点集中抽取全部用户解决方式:
    using (SPSite site = new SPSite("http://localhost"))
    {
        foreach (SPUserSolution solution in site.Solutions)
        {
            Console.WriteLine(solution.Name);
            Console.WriteLine(solution.Status);
        }
    }

    怎样获得场解决方式

            抽取全部场解决方式的代码例如以下:
    foreach (SPSolution solution in SPFarm.Local.Solutions)
    {
        Console.WriteLine(solution.Name);
        Console.WriteLine(solution.SolutionId);
        Console.WriteLine(solution.Status);
    }
            接下来看看怎样通过server端对象模型安装解决方式吧。

    安装沙盒解决方式

            安装解决方式有两步:加入�到库;激活。
            以下是加入�解决方式到库的代码:
    using (SPSite site = new SPSite("http://localhost"))
    {
        SPDocumentLibrary gallery
                  =(SPDocumentLibrary)site.GetCatalog(SPListTemplateType.SolutionCatalog);
        SPFile file = gallery.RootFolder.Files.Add("SandboxedSolution.wsp",
           File.ReadAllBytes("SandboxedSolution.wsp"));
     
        SPUserSolution solution = site.Solutions.Add(file.Item.ID);
    }

    移除沙盒解决方式

            移除解决方式并禁用功能使用下面代码:
    using (SPSite site = new SPSite("http://localhost"))
    {
        SPUserSolution solution = site.Solutions.Cast<SPUserSolution>().
                                                 Where(s => s.Name == "Your Solution").First();
        site.Solutions.Remove(solution);
    }

    安装场解决方式

             安装场解决方式使用下面代码:
    private static void InstallFarmSolution()
    {
        SPSolution solution = SPFarm.Local.Solutions.Add("File Path here");
        solution.Deploy(DateTime.Now, true, GetAllWebApplications(), true);
    }
            我们须要指定解决方式路径。上面的代码让解决方式安装到全部Web应用程序中。GetAllWebApplication()方法主体例如以下:
    public static Collection<SPWebApplication> GetAllWebApplications()
    {
        Collection<SPWebApplication> result = new Collection<SPWebApplication>();
        SPServiceCollection services = SPFarm.Local.Services;
        foreach (SPService s in services)
        {
            if (s is SPWebService)
            {
                SPWebService webService = (SPWebService)s;
                foreach (SPWebApplication webApp in webService.WebApplications)
                {
                    result.Add(webApp);
                }
            }
        }
        return result;
    }

    移除场解决方式

            移除场解决方式成为收回解决方式。这是合适的方法:
    private void RetractFarmSolution(SPSolution solution)
    {
        solution.Retract(DateTime.Now);
    }
            创建Timer job收回解决方式。你能够指定開始收回的时间。
            仅仅从指定Web应用程序移除解决方式,參照这种方法:
    private void RetractFarmSolution(SPSolution solution, Collection<SPWebApplication> webApplications)
    {
        solution.Retract(DateTime.Now, webApplications);
    }

    总结

            本文中,我们学习了怎样使用server端对象模型抽取沙盒解决方式和场解决方式。

    參考:

    关于沙盒解决方式与场解决方式差别,參照http://msdn.microsoft.com/en-us/library/ee361616.aspx
    使用代码激活SharePoint 2010 沙盒解决方式,參照http://msdn.microsoft.com/en-us/library/hh528516(v=office.14).aspx
  • 相关阅读:
    matlab图像处理-中值滤波原理
    typora修改主题和字体
    [NLP] TextCNN模型原理和实现
    [python] 基于词云的关键词提取:wordcloud的使用、源码分析、中文词云生成和代码重写
    基于sklearn和keras的数据切分与交叉验证
    基于TextRank提取关键词、关键短语、摘要
    [强化学习]Part1:强化学习初印象
    Linux多文件按行拼接整合命令paste
    文本匹配算法
    Python如何输出带颜色的文字
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4091314.html
Copyright © 2020-2023  润新知