Advertisement
tankcr

sharepoint connect

Jul 18th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint;
  7. using Microsoft.SharePoint.Administration;
  8.  
  9. namespace SharePoint_Info
  10. {
  11.  
  12.     public class Servers
  13.     {
  14.  
  15.         public event EventHandler TableDataChanged;
  16.  
  17.         private List<Server> tableData;
  18.         public List<Server> TableData
  19.         {
  20.             get { return tableData; }
  21.             set
  22.             {
  23.                 tableData = value;
  24.                 if (TableDataChanged != null)
  25.                 {
  26.                     TableDataChanged(this, EventArgs.Empty);
  27.                 }
  28.             }
  29.         }
  30.  
  31.         public Servers()
  32.         {
  33.  
  34.         }
  35.         public class GetFarm
  36.         {
  37.             public static Servers GetServerList(string caurl)
  38.             {
  39.                 Servers table = new Servers();
  40.                 table.tableData = new List<Server>();
  41.                 Server item = new Server();
  42.                 SPWebApplication oWebApplication = SPWebApplication.Lookup(new Uri(caurl));
  43.                 SPFarm farm = oWebApplication.Farm;
  44.                 foreach (SPServer server in farm.Servers)
  45.                 {
  46.                     item.ServerName = server.DisplayName;
  47.                     item.ServerIP = server.Address;
  48.                     table.TableData.Add(item);
  49.                 };
  50.                 return table;
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement