gpt4 book ai didi

c# - 如何正确使用 SPServiceApplication 集合?

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:33 24 4
gpt4 key购买 nike

我正在尝试编写一个小型控制台应用程序来显示 SharePoint 2010 站点上正在运行的服务应用程序列表。我使用了 Microsoft.SharePoint 和 Microsoft.SharePoint.Administration,但到目前为止我运气不佳。以下是我一直在摆弄的东西。谁能给我一些关于如何正确使用 SPServiceApplicationCollection 的指示?

提前致谢!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ServiceProcess;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

SPServiceApplicationCollection services = new SPServiceApplicationCollection(String, SPFarm.Local.Services);
foreach (SPServiceApplication service in services)
{
Console.WriteLine(service.Name);

if (service is SPWebService)
{
SPWebService webService = (SPWebService)service;

foreach (SPWebApplication webApp in webService.WebApplications)
{
Console.WriteLine(webApp.Name);
Console.ReadLine();
}

}

}
}
}
}

编辑经过一番挖掘/询问后,我想出了一个粗略的解决方案。为了将来引用/任何其他希望做这种事情的人,我可以通过执行以下操作获得已部署服务器的列表以及应用程序名称:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ServiceProcess;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Health;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var solution = SPFarm.Local.Solutions["Your Service Application Name.wsp"];
string serverName = string.Empty;
foreach (SPServer server in solution.DeployedServers)
{
serverName += server.Name;
Console.WriteLine(server.Name);
}

if (solution != null)
{
if (solution.Deployed)
{
Console.WriteLine("{0} is currently deployed on: {1}", solution.Name, serverName);
Console.ReadLine();
}
else
{
Console.WriteLine("Error! Solution not deployed!");
Console.ReadLine();
}
}

}
}
}

最佳答案

经过一番挖掘/四处询问后,我想出了一个粗略的解决方案来满足我的需求。为了将来引用/任何其他希望做这种事情的人,我可以通过执行以下操作获得已部署服务器的列表以及应用程序名称:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ServiceProcess;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Health;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var solution = SPFarm.Local.Solutions["Your Service Application Name.wsp"];
string serverName = string.Empty;
foreach (SPServer server in solution.DeployedServers)
{
serverName += server.Name;
Console.WriteLine(server.Name);
}

if (solution != null)
{
if (solution.Deployed)
{
Console.WriteLine("{0} is currently deployed on: {1}", solution.Name, serverName);
Console.ReadLine();
}
else
{
Console.WriteLine("Error! Solution not deployed!");
Console.ReadLine();
}
}
}
}
}

关于c# - 如何正确使用 SPServiceApplication 集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12407475/

24 4 0
文章推荐: python - 使用Python CGI显示
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com