A new release of Microsoft All-In-One Code Framework is available on August 6th. In this release, we added lots of SharePoint code samples. We expect that its 19 new SharePoint code samples covering would ease your development work.
You can download the code samples using Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates.
If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.
New SharePoint Server Code Samples
Hide Ribbon from anonymous users in SharePoint 2010
C# version: http://code.msdn.microsoft.com/CSSharePointHideRibbonFromA-79dda4e4
VB version: http://code.msdn.microsoft.com/VBSharePointHideRibbonFromA-5e43a687
Call Claim-aware WCF Service from a SharePoint 2010 Claims Site
C# version: http://code.msdn.microsoft.com/CSSharePointCallClaimsAware-8f2c3913
VB version: http://code.msdn.microsoft.com/VBSharePointCallClaimsAware-f26683fc
This sample code will demonstrate how to call a Claims-Aware WCF Service from a SharePoint 2010 Claims Site. We use Service Application Framework (SAF) to host WCF Web Service in IIS. On the caller’s side, we need to use CreateChannelActingAsLoggedOnUser method to send the Claim based SharePoint Logged-on user’s security token to our custom web service. In our custom WCF web service, we need to use System.Threading.Thread.CurrentPrincipal.Identity to get the claim based security token.
Add element under head tag in SharePoint 2010
C# version: http://code.msdn.microsoft.com/CSSharePointAddElementToHea-ac50fcfa
VB version: http://code.msdn.microsoft.com/VBSharePointAddElementToHea-fbe6a0de
The sample demonstrates how to add or modify element of the html head Tag. In the use of master pages, some users may want to customize title, Meta, or other head tags for each page. After walking through this simple demonstration, you can operate the other tags easily.
UpdateTask activity in SharePoint 2010
C# version: http://code.msdn.microsoft.com/CSSharePointUpdateTaskActiv-dd8c6051
VB version: http://code.msdn.microsoft.com/VBSharePointUpdateTaskActiv-f2cfc2f7
The project illustrates how to Use UpdateTask activity in SharePoint Visual Studio Workflow. In this sample, we assume that the approval requires two steps, the first person (the Approver) completes the first step in the approval and then we will re-register the workflow to the second person.
Demo the use of SPCalendarView in SharePoint 2010
C# version: http://code.msdn.microsoft.com/CSSharePointCustomCalendar-0e922479
VB version: http://code.msdn.microsoft.com/VBSharePointCustomCalendar-7a7c89e3
This sample code demonstrates how to use "SPCalendarView" class to develop a custom calendar in a visual web part.
Replicator activity in SharePoint Visual Studio workflow
C# version: http://code.msdn.microsoft.com/CSSharepointrReplicatorActi-d12e1779
VB version: http://code.msdn.microsoft.com/VBSharepointrReplicatorActi-1731dc42
The project shows how to use Replicator activity in a SharePoint Visual Studio workflow. In real world, when we develop an approval workflow, we often need to assign task to multiple approvers dynamically, so we need to use replicator activity.
Get SharePoint List ID and name from List URL
C# version: http://code.msdn.microsoft.com/CSSharepointGetListIDFromLi-354a5a6f
The sample will show you how to get the list ID, name from the list url by using web service. In this sample, we use Lists.GetListCollection Method of list web Services. It will return a System.Xml.XmlNode object. You can get the value of the attribute "DefaultViewUrl" and append it to site url. After that, you should compare the url with your list url, and then find the list ID value.
Remove permission level
C# version: http://code.msdn.microsoft.com/CSSharePointRemovePermissio-993012e5
VB version: http://code.msdn.microsoft.com/VBSharePointRemovePermissio-13bcee45
This sample code demonstrates how to programmatically remove specific permission level from group in SharePoint 2010. Generally, we can remove a specific permission level by removing the group’s role assignments from the target web, list, or item. Also, this sample shows you how to assign specific permission level to the group.
Rename document during upload
C# version: http://code.msdn.microsoft.com/CSSharePointRenameDocumentD-b0db5632
VB version: http://code.msdn.microsoft.com/VBSharePointRenameDocumentD-68ad46da
The sample code will show you how to rename the document using event receiver during upload. We mainly use SPFile.MoveTo method to rename the newly uploaded document. The "MoveTo" method renames the document by moving the file to a specified destination URL.
Pagination using SPquery
C# version: http://code.msdn.microsoft.com/CSSharePointPaginationWebPa-b44c8073
VB version: http://code.msdn.microsoft.com/VBSharePointPaginationWebPa-2d7b2900
This sample code demonstrates how to implement pagination through SPquery. The sample will fetch the list items from a specified web site. You can set how many pages have to be shown for our custom pagination. For e.g., if you have 100 items in a list, and rowlimt=50 then the total number of pages should be 2.