Thursday, 20 February 2014

patterns & practices SharePoint Guidance

patterns & practices SharePoint Guidance​
 
 
Error Logging in SharePoint
http://spmatt.wordpress.com/tag/sharepoint-guidance-library/

SharePoint 2013 development overview



http://msdn.microsoft.com/en-us/library/ff798413.aspx


Put the JavaScript or XAP files in a SharePoint library, and enable binary large object (BLOB) caching. BLOB caching instructs SharePoint to cache BLOB content, such as JavaScript and XAP files, on the SharePoint Web front-end servers. It also enables client browsers to cache the content. If BLOB caching is not enabled, the HTTP header that returns the JavaScript or XAP resources to the client will instruct the browser not to cache the files. It does this by including a cache-control: private directive and by setting an expiration time in the past. As a result, neither the client browser nor the web front-end server will cache the content, which instead will be retrieved from the content database on every request. BLOB caching is a SharePoint Server 2010 feature and must be enabled in the configuration files for the SharePoint web applications, so to some degree you are at the mercy of the farm administrator. For more information on BLOB caching, see Disk-Based Caching for Binary Large Objects.
http://msdn.microsoft.com/en-us/library/aa604896.aspx 

REST in SP2010



SHAREPOINT GUIDANCE FOR SHAREPOINT 2013
http://graegert.de/blog/sharepoint-guidance-for-sharepoint-2013/ 

SharePoint Development Debugging

I've been reading a lot of posts on how to get debugging going when attaching to the w3wp.exe process.

Disable 'Enable Just My Code' in Visual Studio

This blog post started me off in the correct direction by setting the Tools | Options | Debugging setting correctly.

Modify the web.config

Furthermore, it prompted me to change the web.config value from debug="false" to debug="true". The web.config file can be found in the Inetpub\wwwroot\wss\VirtualDirectories\ folder, each folder in there maps to an IIS Web Application which you can find by going to IIS Manager and looking at the Home Directory.
To get full blown ASP.NET errors rather than SharePoint branded "useless" ones follow these steps:

Setting CallStack=true

By default, WSS will redirect a user to the error page whenever an unhandled exception is encountered during the render cycle.  To disable this behavior, open your web.config and set CallStack="true" in the <SafeMode> node.  This allows you to see a typical Asp.net error page.

Setting customErrors mode...

The next step would be set mode="Off" in the <customErrors> node.  This instructs Asp.net to show you a complete error report rather than a generic "Server Error" page.

Creating pdbs

For each project you wish to debug, you need to ensure that you are creating pdbs. I am using the really cool stsdev app to create my projects and had to modify it to create pdbs by going to Project Properties and on the Build tab in the Output Section click the Advanced button. 
Then ensure that Debug Info is set to pdb-only. 


Attach to Process

The author of the previous referenced post also pointed me to running iisapp on the command line to output a list of all the running instance to know which process to attach to:
Then when you select Debug | Attach to Process the ID matches to the PID in the output of iisapp. Note you need to check 'Show processes from all users' as w3wp.exe will be typically running as another account.

You can check that you have the correct id by pressing CTRL-ALT-U and this will list all the Modules that are loaded with statuses on the symbols that are available (e.g. that when you create a breakpoint it'll work rather than giving you a 'No symbols loaded' errror).

Sometimes there are just too many instances of w3wp.exe to pick from. An easy way to just let the system sort things out for you, rather than inserting a breakpoint, is to insert the following line in your code:
System.Diagnostics.Debugger.Break();

Notes for Visual Studio Debugging Newbies


Once you are actually debugging and can step through code after it breaks on a breakpoint...you can also use the Immediate window to inspect objects by pressing CTRL-ALT-I. From here you can get up intellisense on any object in context which is a great way to inspect things like whether a SharePoint list has an Event Receiver on it or not. 
 

The web server process that was being debugged has been terminated by Internet Information Services (IIS)

If you are debugging in IIS7.0 you will find that you will receive this error if you leave it on a break point for too long.



 
Unknown macro: {NewCode}
---------------------------
Microsoft Visual Studio
---------------------------
The web server process that was being debugged has been terminated by Internet Information Services (IIS). This can be avoided by configuring Application Pool ping settings in IIS. See help for further details.
---------------------------
OK Help
---------------------------

The Resolution is to follow these steps on MSDN - Error: Web site worker process has been terminated by IIS
 


Optimizing SharePoint sites



source: https://www.nothingbutsharepoint.com/sites/devwiki/SP2007Dev/Pages/SharePoint%20Development%20Debugging.aspx

Get SharePoint fields internal name

Use this powershell command:
$list = (Get-SPWeb "http://portal.contoso.com").Lists["Demo List"]
$list.Fields | ?{$_.title -eq "Title"} | FT Title, InternalName
Example:
PS C:\Users\spt.prod.installer> $list = (Get-SPWeb "http://emflow").Lists["work items"]
PS C:\Users\spt.prod.installer> $list.Fields | ?{$_.title -eq "Title"} | FT Title, InternalName
Title                                   InternalName
-----                                   ------------
Title                                   Title
Title                                   LinkTitleNoMenu
Title                                   LinkTitle
Title                                   LinkTitle2


PS C:\Users\spt.prod.installer> $list.Views | FT viewfields

ViewFields
----------
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Modified, Activity_x0020_ID, Status, Entry_x0020_Date...}
{Modified, Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_...
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Modified, Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_...
{Modified, Activity_x0020_ID, Status, Entry_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_Date, SLA_...
{Activity_x0020_ID, Assign_x0020_Bucket_x003a_Group_, Entry_x0020_Date, SLA_...
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}
{Activity_x0020_ID, Status, Entry_x0020_Date, SLA_x0020_Date...}

PS C:\Users\spt.prod.installer>

SharePoint 2013 REST API endpoint links

http://htvspt13dev1:1020/_api/web/lists/getByTitle('Events')/items
http://htvspt13dev1:1020/Roblog/_api/web/lists/getByTitle('posts')
 SharePoint REST request syntax


To access a specific site collection, use the following construction:
http://htvspt13dev1:1020/_api/site
To access a specific site, use the following construction:
http://htvspt13dev1:1020/_api/web

Feature area
Access point
Site
http://server/site/_api/site 
Web
http://server/site/_api/web
User Profile
http:// server/site/_api/SP.UserProfiles.PeopleManager
Search
http:// server/site/_api/search
Publishing
http:// server/site/_api/publishing


Client object model API
REST endpoint
ClientContext.Web.Lists
http://server/site/_api/web/lists
ClientContext.Web.Lists[guid]
http://server/site/_api/web/lists(‘guid’)
ClientContext.Web.Lists.GetByTitle("Title")
http://server/site/_api/web/lists/getbytitle(‘Title’)

SharePoint REST parameter syntax

SharePoint REST service method parameter syntax
http://htvspt13dev1:1020/_api/web/lists/getbytitle('Events')/fields/getByTitle('Title')

To construct URIs that correspond to static methods or properties, use the corresponding API name from the ECMAScript object model, starting with the namespace declaration and using dot notation. For example, SP.Utilities.Utility.getImageUrl(imageName) in the ECMAScript client object model would have the following REST equivalent:
http://server/site/_api/SP.Utilities.Utility.getImageUrl('imageName')

http://htvspt13dev1:1020/Roblog/Lists/Photos/_api/SP.Utilities.Utility.getImageUrl('CEOBlogImg.png')

The following example shows how to retrieve all of a list’s items.
 
url: http://site url/_api/web/lists/GetByTitle(‘Test')/items
method: GET
headers:
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or “application/atom+xml”

The following example shows how to retrieve a specific list item.

url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)
method: GET
headers:
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or “application/atom+xml”


http://htvspt13dev1:1020/Roblog/_api/web/lists/getByTitle('photos')/items(1)

URI Conventions - Filter System Query Option ($filter)


http://msdn.microsoft.com/en-US/library/office/jj163227#bkmk_constructquery


web/lists/getByTitle('ListName')/Items?$select=Title&$filter=AverageRating gt 3

source: http://msdn.microsoft.com/en-us/library/office/dn292556.aspx


Making the Newsfeed web part available outside of My Sites in SharePoint 2013

This is actually a web part titled Newsfeed, and can be found under the Social Collaboration category. Now, you may want to have the Newsfeed on the homepage of your main portal rather than My Site. To make this web part available in your site collection, you will need to activate the feature with title “My Site Layouts Feature“. This is a hidden site collection feature so you will need to use SharePoint Manager or PowerShell. The feature ID is 6928B0E5-5707-46a1-AE16-D6E52522D52B. Its physical location under {SharePointRoot} is TEMPLATE\FEATURES\MySiteLayouts.
This feature brings a number of other web parts and also the MySite.master master page. Check its manifest for further details.
Enable-SPFeature -Identity 6928B0E5-5707-46a1-AE16-D6E52522D52B -Url http://yourSiteCollection

The SiteFeedWebPart is in the Microsoft.SharePoint.Portal.WebControls namespace.

Making My Tasks web part available outside of MySites

The My Tasks web part exists in MySites by default, and can be found under the Content Rollup category. To make this web part available outside of MySites, activate the “My Tasks Dashboard” feature.

This is a hidden Web-scoped feature. The feature ID is 89D1184C-8191-4303-A430-7A24291531C9, and the feature folder under SharePointRoot is MyTasksDashboard.

http://bernado-nguyen-hoan.com/2013/03/03/making-my-tasks-web-part-available-outside-of-mysites/

source: http://bernado-nguyen-hoan.com/2013/02/12/making-the-newsfeed-web-part-available-outside-of-my-sites-in-sharepoint-2013/

How to Get Login Name and Display Name using SharePoint 2013 REST API

jQuery.ajax({
    url: "/SiteName/_api/web/lists/getbytitle('ListName')/items",
    type: "GET",
    headers: { "Accept": "application/json;odata=verbose" },
    success: function(data, textStatus, xhr) {
        var dataResults = data.d.results;
        var resultId = dataResults[0].AuthorId.results[0];        
        getUser(resultId)
    },
    error: function(xhr, textStatus, errorThrown) {
        alert("error:"+JSON.stringify(xhr));
    }
});

function getUser(id){
var returnValue;
  jQuery.ajax({
   url: "http://YourSite/_api/Web/GetUserById(" + id + ")",
   type: "GET",
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(data) {
           var dataResults = data.d;
      //get login name  
      var loginName  = dataResults.LoginName.split('|')[1];
      alert(loginName);     
      //get display name
      alert(dataResults.Title);
   }
 });
}
How to Get Login Name and Display Name using SharePoint 2013 REST API
http://www.codeproject.com/Articles/692289/How-to-Get-Login-Name-and-Display-Name-using-Share

AngularJS

SharePoint 2013 Apps and AngularJS - The basics
http://blog.meligo.be/2013/08/sharepoint-2013-apps-and-angularjs-the-basics/
SharePoint Hosted App with CSOM & AngularJS for MVC Javascript
http://www.jeremythake.com/2013/10/sharepoint-hosted-app-with-angularjs-for-mvc-javascript/
Marc D Anderson
http://sympmarc.com/
Mark Rackley
http://www.sharepointhillbilly.com/default.aspx
Andrew Connell
http://www.andrewconnell.com/
SharePoint Hosted App with CSOM & AngularJS for MVC Javascript
http://www.jeremythake.com/2013/10/sharepoint-hosted-app-with-angularjs-for-mvc-javascript/