Sunday, June 15, 2014

Sharepoint 2010\2013 List ,Libraries and Events

Agenda for Sharepoint 2010\2013

1.List Instances
2.Document Libraries
3.Events in SharePoint 2013
4.Server-Side Event Receivers
5.Remote Event Receivers

List instances :

SharePoint 2010 introduced the capability to have a relationship behavior enforced by Lookup columns

New investments:

Projected fields into child lists
Joins
Relational integrity between parent & child lists

Introduces new security considerations and possible issues

Projected Fields

1.Extra field pulled from parent list into view of child list
2.Via browser interface, users add a lookup from another list
3.Then, user can select a secondary lookup field to pull into the child list

Join in List :


1.With relational lists, SharePoint Foundation 2010 added support for joins
2.Joins can only be implemented by developers using the API, CAML or SharePoint Designer

3.Join related properties on SPQuery:

SPQuery.Join
SPQuery.ProjectedFields

4.Maximum number view fields selected for a joined of joins on a list view = 6

     Exception thrown if user tries to select fields from more than six fields from the joined lists
     If no view fields specified (maximal view), only the first 6 pulled

Tip: Use LINQ to SharePoint instead of CAML to join two lists in code

Large List :



SharePoint 2010 added self-monitoring protection against expensive queries

Expensive query: one that returns lots of data

Platform Investments:
Configuration options for administrators per Web application

Site collection & list administrators can request privileged operations (expensive queries)


SPList.IsThrottled: when true, list contains more items than the configured limit to be considered a “large list



Enables developers to ignore query safety checks and run an unsafe query via SPQuery or SPSiteDataQuery

Requires special priv. 2 different limits:

Normal user – 5,000 items
Super user – 20,000 items

Configure time window when to allow expensive queries



Document Library :

SPDocumentLibrary inherits from SPList


SPWeb site = SPContext.Current.Web;

        foreach (SPList list in site.Lists)

{

if (list is SPDocumentLibrary && !list.Hidden)

{

SPDocumentLibrary library = list as SPDocumentLibrary;

SPFolder folder = library.RootFolder;

TreeNode libraryNode = new TreeNode

(

library.Title, library.DefaultViewUrl,
"~/_layouts/15/images/icons/folder.png");

LoadFolderNodes(folder, libraryNode); treeSitesFiles.Nodes.Add(libraryNode);

} }


 
Adding document programmatically :

 SPSite siteCollection = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
Guid libraryID = new Guid(lstTargetLibrary.SelectedValue);
SPDocumentLibrary library = site.Lists[libraryID] as SPDocumentLibrary;

String dcumentName = txtFileName.Text;string libraryRelativePath = library.RootFolder.ServerRelativeUrl;
string libraryPath = siteCollection.MakeFullUrl(libraryRelativePath);
string documentPath = libraryPath + "/" + documentName;

Stream documentStream = new MemoryStream();
StreamWriter writer = new StreamWriter(documentStream);
writer.Write(txtDocumentBody.Text);
writer.Flush();

Hashtable docProperties = new Hashtable(); docProperties["vti_title"] = "This is a test title";
docProperties["Color"] = "Green";site.Files.Add(documentPath, documentStream, docProperties, true);

Response.Redirect(libraryPath);



Provisioning Document Libraries
 

<?xml version="1.0" encoding="utf-8"?>
<ListInstance Id="Proposals"
TemplateType="101"
Title="Proposals"
Description="Document Library for proposals"
OnQuickLaunch="True"
Url="Proposals">
</ListInstance>
<Module Name="TestData" List="101" Path="TestData" Url="Proposals" >
    <File Url="Adventure Works Proposal.docx" Type="GhostableInLibrary" />
    <File Url="Contoso Proposal.docx" Type="GhostableInLibrary" />
    <File Url="Wingtip Toys Proposal.docx" Type="GhostableInLibrary" />
</Module>

<Module Name="WordTemplate" List="101" Url="Proposals/Forms">
   <File Url="ProposalTemplate.dotx" Type="Ghostable" />
</Module>


Events in SharePoint 2013

Sharepoint 2013 is having 2 types of  events
1. Server side events.
2.Remote events.

Server side events :
     Pre-Action & Post-Action Events
       Site Collection & Site Events
       Feture Events
       List & Library Events
       Schema Events
       List Item Events
       Workflow Events

Remote Events  :
   
      Introduced in SharePoint 2013
      App Lifecycle Events
      Events within Apps
      External Content Type Events

Server-Side Events
 
Site
Features
List\Library
List\Library schema
List Item
 
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
 

 
Events are useful :

Data validation
Processes that are not longer-running in duration
Processes that do not require user or external system input or involvement
Apps do not permit server-side events


Remote Event Receivers
 
Many events have a pre & post side to them
Many pre-events cancellable with message / error page
 
Site
List / Library
List / Library Schema
List item
SharePoint App
Create
 Move
 Delete
 
Create
 Delete
 
Create
 Update
 Delete
 
Create
 Update
 Delete
 Move
 CheckIn
 UnCheckIn
 CheckOut
 Attachment Added
 Attachment Removed
 File Moved
 File Converted
 
Install
 Update
 Uninstall
 
 

List Event Registration

Declaratively or programmatically register remote event receivers with a list definition

Unlike server-side events, use URL for endpoint rather than assembly & type containing event


using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.RootWeb)
{
      SPList list = web.Lists[listName];

         list.EventReceivers.Add(            SPEventReceiverType.ItemAdded,rEndpoint);

}

}

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="10000">
    <Receiver>
      <Name>AnnouncementItemAdding</Name>
      <Type>ItemAdding</Type>
      <SequenceNumber>10000</SequenceNumber>
      <Url>~remoteAppUrl/AnnouncementItemAddingRER.svc</Url>
    </Receiver>
  </Receivers>
</Elements>

App Lifecycle Event Registration

Declaratively register remote event receivers
Definitions found in AppManifest.xml

 
<Properties>
  <Title>App Lifecycle Event</Title>
  <StartPage>~appWebUrl/Pages/Default.aspx?{StandardTokens}</StartPage>
  <InstalledEventEndpoint>~remoteAppUrl/AppEventReceiver.svc</InstalledEventEndpoint>
  <UninstallingEventEndpoint>~remoteAppUrl/AppEventReceiver.svc</UninstallingEventEndpoint>
  <UpgradedEventEndpoint>~remoteAppUrl/AppEventReceiver.svc</UpgradedEventEndpoint>
</Properties>

IRemoteEventService Interface

Synchronous & asynchronous events are supported


public class AppEventReceiver : IRemoteEventService

{

public SPRemoteEventResult ProcessEvent(RemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
result.Status = SPRemoteEventServiceStatus.Continue;

return


result;

}
public

void ProcessOneWayEvent(RemoteEventProperties properties)

{

}


Sharepoint 2013 Remote event receivers

 
 

No comments:

Post a Comment