Hard learned SharePoint development tips

38
SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013 ZAGREB, NOVEMBER 27-28 2013 Hard learned SharePoint dev tips SAHIL MALIK WWW.WINSMARTS.COM @SAHILMALIK

description

SharePoint development is a pain. You need a big VM, lots of RAM, can’t use any of the new fun stuff they show you at TechED. The API can be cumbersome, documentation can be as trustworthy as your average Russian banker. How is a SharePoint developer to be productive and write reliable code in such a hostile environment? This hard learned session is both funny and sad at the same time where Sahil describes some of his painfully learnt development lessons. Sahil Malik

Transcript of Hard learned SharePoint development tips

Page 1: Hard learned SharePoint development tips

SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013ZAGREB, NOVEMBER 27-28 2013

Hard learned SharePoint dev tips

SAHIL MALIK

WWW.WINSMARTS.COM

@SAHILMALIK

Page 2: Hard learned SharePoint development tips

sponsors

Page 3: Hard learned SharePoint development tips

C:\>whoami

11xMVP

15xAuthor

Pluralsight Author

Microsoft Metro Trainer

Funny and Honest

HTTP://BLAH.WINSMARTS.COM@SAHILMALIK

Page 4: Hard learned SharePoint development tips

Hard learned SharePoint dev tips Hard learned CSOM and REST

0945AM 0345PM

Page 5: Hard learned SharePoint development tips

Lists and Document Libraries

Page 6: Hard learned SharePoint development tips

Lists live in SPWebs

Page 7: Hard learned SharePoint development tips

dbo.AllLists

Page 8: Hard learned SharePoint development tips

Primary Key for AllLists

Page 9: Hard learned SharePoint development tips

Content Types – will make performance worse

Page 10: Hard learned SharePoint development tips

tp_Fields

Page 11: Hard learned SharePoint development tips

dbo.AllUserData

Page 12: Hard learned SharePoint development tips

My Test List

Page 13: Hard learned SharePoint development tips

Example

Page 14: Hard learned SharePoint development tips

Example 2

Page 15: Hard learned SharePoint development tips

tp_ColumnSet

Page 16: Hard learned SharePoint development tips

Sparse Columns

Page 17: Hard learned SharePoint development tips

AllUserDatatp_ID identify the list item

tp_GUID To uniquely identify the list item

tp_ListId To identify which list the item belongs to.

tp_SiteId To identify which site the item belongs to. It is the value of ‘Id’ in ‘AllSites’ table

tp_RowOrdinal Zero based ordinal index in the set of rows representing the list item

tp_Author User who created the list item

tp_Editor User who last edited the list item

tp_Modified Modified date

tp_Created Created date

tp_DeleteTransactionID Not 0x if the item is in recycle bin

tp_IsCurrentVersion (bit) 1 or 0, identifying latest version

nvarchar1..64 Stores values of application fields of type nvarchar

ntext1..32 Stores application fields of type ntext

bit1..16 Application fields of type bit

datetime1..8 Application fields of type datetime

Page 18: Hard learned SharePoint development tips

AllUserData

float 1..12 Application fields of type float

Int1..16 Application fields of type int

sql_variant1..8 Application fields of type sql_variant

Page 19: Hard learned SharePoint development tips

AllUserData - takeaways

Page 20: Hard learned SharePoint development tips

Now lets talk documents!

Page 21: Hard learned SharePoint development tips

Test Data

Page 22: Hard learned SharePoint development tips

How are documents stored?

Page 23: Hard learned SharePoint development tips

Document Storage

Page 24: Hard learned SharePoint development tips

DocStreams

Page 25: Hard learned SharePoint development tips

Scientifically accurate picture of RBS

Page 26: Hard learned SharePoint development tips

Document Storage – Lessons Learnt

Page 27: Hard learned SharePoint development tips

Careful of iterators!

Avoids multiple calls to DB

Does not create SPListItemCollection over and over again

Page 28: Hard learned SharePoint development tips

Number of Items in a list

Page 29: Hard learned SharePoint development tips

SPQuery is your friend2147483648

And its getting every single column!

Page 30: Hard learned SharePoint development tips

Avoid reloading objects

Page 31: Hard learned SharePoint development tips

SharePoint objects are not threadsafe!

Page 32: Hard learned SharePoint development tips

Getting a list

proc_EnumLists

proc_MapUrlToListAndView

proc_EnumLists loads all information of all lists in the SPWeb object, and then does a .Title comparison to find the

list you need.

proc_MapUrlToListAndView finds the GUID for the associated list, and then loads the metadata for the list you

need.

Page 33: Hard learned SharePoint development tips

Deleting Items

Page 34: Hard learned SharePoint development tips

Good vs Evil

Evil Good

SPList.Items.Count SPList.ItemsCount

SPList.Items[Guid] SPList.GetItemByUniqueId(Guid)

SPList.Items[Int32] SPList.GetItemById(Int32)

SPList.Items.GetItemById(Int32) SPList.GetItemById(Int32

SPList.Items.NumberOfFields SPQuery + ViewFields

SPList.Items.ReorderItems Use SPQuery.ListItemCollectionPosition to do paging

SPFolder.Files.Count SPFolder.ItemCount

Page 35: Hard learned SharePoint development tips

.Dispose

Page 36: Hard learned SharePoint development tips

.Dispose

Page 37: Hard learned SharePoint development tips

questions?

HTTP://BLAH.WINSMARTS.COM

@SAHILMALIK

Page 38: Hard learned SharePoint development tips

thank you.

SHAREPOINT AND PROJECT CONFERENCE ADRIATICS 2013ZAGREB, NOVEMBER 27-28 2013