Benutzer:MovGP0/SharePoint

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


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

[Bearbeiten | Quelltext bearbeiten]
Client Object Model
Client Server
ClientContext SPContext
Site SPSite
Web SPWeb
List SPList
ListItem PpListItem
Field SPField

Server Side Object Model (SSOM)

[Bearbeiten | Quelltext bearbeiten]
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)

[Bearbeiten | Quelltext bearbeiten]
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()
$.ajax({
   url: "http://mysite/_api/web/lists",
   type: "GET",
   contentType: "application/json;odata=verbose",
   headers: {
      "ACCEPT", "application/json;odata=verbose", 
      "Authorization", "Bearer" + accessToken
   }
})
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><RowLimit>100</RowLimit></View>");
this.listItemCollection = list.getItems(camlQuery);
var customers = customerList.Take(100).Select();

Server-Side Events

[Bearbeiten | Quelltext bearbeiten]
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.)
  • 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();
   }
}
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

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
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
    }
}
  1. OWSSVR.dll tricks. In: Ahmed's SharePoint Globe. 13. Dezember 2010, abgerufen am 21. Mai 2014 (englisch, Export von Listdaten als XML).
  2. Walkthrough: Import Items from an Existing SharePoint Site. In: MSDN. Microsoft, abgerufen am 2. Juni 2014 (englisch).
  3. http://techtrainingnotes.blogspot.co.at/2007/12/exploring-sharepoint-cmp-backup-files.html
  4. http://sharepointnomad.wordpress.com/2012/05/03/how-to-export-and-import-lists-and-libraries-from-a-sharepoint-2010-site-using-powershell/
  5. http://msdn.microsoft.com/en-us/library/office/jj860569.aspx#Reference
  6. http://msdn.microsoft.com/en-us/library/office/dn499819.aspx#bk_Web