Benutzer:MovGP0/SharePoint

aus Wikipedia, der freien Enzyklopädie
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Begriffe

Farm
Site (Site Collection)
Web (Site)
ListTemplate
Vorlage für Menge an Listenspalten
keine Bindung nach Erstellung der Liste
ContentType (Inhaltstyp)
Vorlage für Menge an Listenspalten
starke Bindung nach Erstellung der Liste
List Type Type ...
ListItem Value Value ...
ListItem Value Value ...

Working with SharePoint Data

Client Object Model
Client Server
ClientContext SPContext
Site SPSite
Web SPWeb
List SPList
ListItem PpListItem
Field SPField

Server Side Object Model (SSOM)

Query Command
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

using(var site = new SPSite(mySiteUrl))
using(var web = site.RootWeb)
{
   foreach(ver list in site.Lists)
   {
      foreach(var item in list.Items)
      {
         // ...
      }
   }  
}
using(var site = new SPSite(siteUrl))
using(var web = site.OpenWeb()) // or: site.RootWeb
{
   var list = mySPWeb.Lists["Products"];
   var newListItem = products.Items.Add();
   newListItem["Product_Name"] = "Salmon";
   newListItem["Product_SKU"] = "SLM-30969";
   newListItem.Update();
}

Client Side Object Model (CSOM)

C# F#
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Runtime;

private static void Load<T>(ClientContext context, T item)
   where T:ClientObject
{
   context.Load<T>(item);
   context.ExecuteQuery();
}

using(var context = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
   var site = context.Site;
   Load(context, site);
   
   var web = site.RootWeb;
   Load(context, web);
   Load(context, web.Lists);
   
   var departmentList = web.List.GetByTitle("Department");
   Load(context, departmentList);


   // CAML Query
   var employeesFieldQuery = new CamlQuery()
   {
      ViewXml = "<View><Query><Where>...</Where></Query></View>"; // TODO: check this
   };
   var employeeList = departmentList.GetItems(employeesFieldQuery);
   Load(context, employeeList);

   // Filter
   var employeeList = departmentList.GetItems(employeesFieldQuery);
   context.Load(employeeList, list => list.Fields.Where(field => field.Title == "Employees"));
   context.ExecuteQuery();


   IEnumerable<FieldUserValue> employees = item["Employees"] as FieldUserValue[]; 
   foreach(var employee in employees)
   {
      var groups = clientContext.Web.SiteGroups;
      var group = groups.GetById(employee.LookupId);
      var users = group.Users;

      context.Load(users); // TODO: load only the specific user based on LoginName/LookupValue
      context.ExecuteQuery();
      
      foreach (var user in users.Where(u => u.LoginName == employee.LookupValue))
      {
         Console.WriteLine("User: {0}  ID: {1} Email: {2} Login Name: {3}", user.Title, user.Id, user.Email, user.LoginName);
      }
}
#r "..\lib\Microsoft.SharePoint.Client.dll"
#r "..\lib\Microsoft.SharePoint.Client.Runtime.dll"

open Microsoft.SharePoint.Client

let private load (context: ClientContext) (item: `a) = 
   context.Load item
   context.ExecuteQuery ()

[<EntryPoint>]
let main = 
   // define parameters
   // ...   

   // define context
   use context = new ClientContext(siteUrl)
   context.Credentials <- new NetworkCredential(user, password, domain)

   // load site
   let site = context.Site
   load context site
   
   // load web
   let web = site.RootWeb
   load context web
   let webTitle = web.Title 
   
   // load context
   load context web.Lists
   for list in web.Lists do
      printf "List Title: %s" list.Title

   // load list
   let meetings = web.Lists.GetByTitle "Meetings"
   context.Load meetings

   // make query and load items
   let query = new CamlQuery()
   query.ViewXml <- "<View><Query><OrderBy>..." // use Camlex.NET to build query
   let meetingItems = meetings.GetItems query
   load context meetingItems
   
   for meeting in meetingItems do 
      printf "Meeting: %s" meeting.["Title"].ToString()

jQuery

$.ajax({
   url: "http://mysite/_api/web/lists",
   type: "GET",
   contentType: "application/json;odata=verbose",
   headers: {
      "ACCEPT", "application/json;odata=verbose", 
      "Authorization", "Bearer" + accessToken
   }
})

CAML

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><RowLimit>100</RowLimit></View>");
this.listItemCollection = list.getItems(camlQuery);

LINQ

var customers = customerList.Take(100).Select();

Server-Side Events

Server-Side Events
Site Feature List, Library List, LibarySchema ListItem Workflow
  • Create
  • Move
  • Delete
  • Install
  • Uninstall
  • Activate
  • Deactivate
  • Create
  • Delete
  • Create
  • Update
  • Delete
  • Create
  • Update
  • Delete
  • Move
  • CheckIn
  • UnCheckIn
  • CheckOut
  • Attachment Added
  • Attachment Removed
  • File Moved
  • File Converted
  • Start
  • Postpone
  • Complete
  • Meist auch Pre- and Post-Events verfügbar (zB. Cancel in Preevent)
  • Validation
  • kurze Laufzeit!
  • kein Warten auf Benutzereingaben
  • nur für SP Solutions; nicht für SharePoint Apps verfügbar
  • erbt von Unterklasse von SPEventReceiverBase (SPItemEventReceiver, SPListEventReceiver, etc.)

Event Receiver

  • NewProjectEvent Receiver
  • select events to handle
  • implement logic
public class SPEventReceiver : SPItemEventReceiver
{
   base.ItemAdded(properties);
   LogAndAnnouncementEvent(properties);
}

private void LogAnAnnouncementEvent(SPItemEventProperties properties)
{
   var eventTitle = properties.ListTitle;
   var siteUrl = "http://mysharepoint/site/";
   using(var site = new SPSite(siteUrl))
   {
      var list = site.Lists["TestList"];
      var newItem = list.Items.Add();
      newItem["Title"] = string.Format("Event triggered from list {0}", eventTitle);
      newItem.Update();
   }
}

Export/Import

Befehle mit owssvr.dll[1]
Befehl Beschreibung
http://server/site/_vti_bin/owssvr.dll?Cmd=Display&List={ListGuid}&Query=*&XMLDATA=TRUE Exportiert SharePoint Liste und das zugehörige XSD
http://server/site/_vti_bin/owssvr.dll?Cmd=Display&List={ListGuid}&View={ViewGuid}&XMLDATA=TRUE Exportiert alle SharePoint Listen die zur View gehören
http://server/site/_vti_bin/owssvr.dll?Cmd=ExportList&List={ListGuid} Exportiert Definition einer SharePoint Liste
http://server/site/_vti_bin/owssvr.dll?Cmd=GetProjSchema Exportiert die onet.xml (Site Definition) welche zum Erstellen der Website benötigt wird
http://server/site/_vti_bin/owssvr.dll?Cmd=GetProjSchema&SiteTemplate=fldtypes Exportiert Field Types die im SharePoint registriert sind.
Exportieren einer WSP-Datei[2]
1. Site als Template exportieren 2. Site als WSP downloaden

Site Settings
SiteActions
Save site as template[a 1]

Site Actions
Site Settings
Got to top level site settings
Site Collection Administration
Galleries
Solutions
→ Template auswählen
Save

  1. wenn Publishing Feature aktiv ist, ist der Menüpunkt „Save site as template“ nicht verfügbar.
SharePoint CMP Export Files[3][4]
Export als Backup Import

→ Central Administration
→ Backup and Restore
→ Export a site or list

Import-SPWeb http://server/site -patch c:\backups\Site.cmp -updateversions overwrite

Web Services

REST Services

REST core endpoints[5]
Verb URL
POST http://<sitecollection>/<site>/_api/web/getchanges(changequery)
GET, POST http://<sitecollection>/<site>/_api/web/eventreceivers
DELETE, MERGE, POST, PUT http://<sitecollection>/<site>/_api/web/eventreceivers(eventreceiverid)
GET, POST http://<sitecollection>/<site>/_api/web/features
POST http://<sitecollection>/<site>/_api/web/features(featureid)
GET, POST http://<sitecollection>/<site>/_api/web/RecycleBin
DELETE, POST http://<sitecollection>/<site>/_api/web/RecycleBin(recyclebinitemid)
POST http://<sitecollection>/<site>/_api/web/RegionalSettings
POST http://<sitecollection>/<site>/_api/site
GET, POST http://<sitecollection>/<site>/_api/web/RegionalSettings/TimeZones
POST http://<sitecollection>/<site>/_api/web/RegionalSettings/TimeZones(timzoneid)
GET, POST http://<sitecollection>/<site>/_api/web/GetAvailableWebTemplates(languageid,includecrosslanguage)
POST http://<sitecollection>/<site>/_api/web/GetAvailableWebTemplates(languageid,includecrosslanguageincludecrosslanguage})/getbyname(templatename)
Webs API[6]
Verb URL

Email Settings

Guid siteID = SPContext.Current.Site.ID;
string GetSMTPHostName()
{
    using (var site = new SPSite(siteID))
    {
      return site.WebApplication.OutboundMailServiceInstance.Parent.Name; // smtp server name
    }
}
string GetFromEmailID()
{
    using (var site = new SPSite(siteID))
    {
      return site.WebApplication.OutboundMailSenderAddress; // from email sender name
    }
}

Links

Quellen