标签:sharepoint 解决方案 代码
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); }接下来看看如何通过服务器端对象模型安装解决方案吧。
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收回解决方案。你可以指定开始收回的时间。
private void RetractFarmSolution(SPSolution solution, Collection<SPWebApplication> webApplications) { solution.Retract(DateTime.Now, webApplications); }
如何用C#代码管理SharePoint解决方案,布布扣,bubuko.com
标签:sharepoint 解决方案 代码
原文地址:http://blog.csdn.net/crazygolf/article/details/37816163