Developer’s Tools: How To Generate Basic Authentication Token

This demo is about another tool that I worked out during an assignment while working with an integration scenario using web services supporting Basic Authentication.

Problem with basic authentication is that you have to keep username and password stored somewhere in order to generate the authentication token.

Since I was integrating external web services with SharePoint so I felt to delegate the Token Generation Process to an external tool and consume the Authentication Token directly with out keep user name and password to be stored in the code itself.

To run this demo I have created a simple interface that takes username and password as input and generates the Basic Authentication Token and will display it in “Authentication Token” section

1

Now let’s discuss the code behind this functionality:

Step 1 is registering button click event by mapping a function “get Token”

Step 2 is calling “getBasicAuthenticationToken” function by passing user name and password

Step 3 is preparing format required to convert plain text into hash value in base-64 format

Step 4 is calling JavaScript function “btoa” which will encode the plain text into “base-64” format which is a required hash value to prepare Basic Authentication Token.

“Basic” is prefixed to the hash value to comply with Basic Authentication Token Standards

2

That is it for the code.

Now when we click “Get Authentication Token” button we will see the authentication token in the “Authentication Token” section.

3

This token can be used for any Web Service supporting basic authentication, and this strategy can be merged with other functionalities too in order to generate this token on the fly.
Hope you find it helpful.

SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 4

In the previous article SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 3 of this series on the Workflow migration Process we saw the execution of Steps 5 & 6 for the process.

In this article we are going to see the execution of Steps 7 & 8 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 7: Destination Site – Provision Workflow Export File

Once we are done successfully with the deployment of Content Type in Destination Site “Site002” then next move is to provision the Workflow export file that we have got from “Step 5” earlier

Here we will be using PowerShell Commands to get it deployed. We will be making use of “Add-SPSolution” & “Install-SPSolution” Cmdlets as shown below-

40

And that’s all. We are all done with the export process and now it time to finally test it in Destination Site “Site002”

Step 8: Destination Site – Test Workflow

In order the functioning of the Workflow do as follows-

  • Launch SharePoint Designer 2013
  • Connect to Destination Site “Site002”
  • Click on “Workflow” link in the left navigation

There we can see the “CustomerLogs” workflow under “Reusable Workflow” list

41

Now visit “CustomerCT” using Site Settings > Site Content Types

42

  • Click on the Content Type
  • Click on Workflow Settings

43

Click “Add a workflow” link to choose the workflow to associate with the content type

44

From the list of available workflows choose “CustomerLogs” and give it a logical name of your choice

45

That is how we get the workflow associated with the content type.

46

Now we need to create a list and add this content type to the list as we did it earlier

And finally you can create the item based on this content type

47Add some values and save the item

49

Once the item is created we can start the workflow as shown in the following steps-

Click on “Workflows” link

50

Start the “Log Customers” Workflow on the item

51

52

Once completed see for the status of the Workflow and the message logged by it in the history log

53

54

And we got the Workflow export process working like a charm.

That is all for this demo.

Hope you find it helpful.

 

SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 3

In the previous article SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 2 of this series on the Workflow migration Process we saw the execution of Steps 3 & 4 for the process.

In this article we are going to see the execution of Steps 5 & 6 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 5: Source Site – Export Workflow

So up till now we have tested the workflow and seem it is working all fine

Now finally it is time to move it out of Source Site “Site001”

  • Launch the SharePoint Designer 2013
  • Click on the Workflow in left navigation
  • Select “CustomerLogs” Workflow
  • Click on “Save as Template” from the Ribbon Control

33

This will export the workflow as .WSP file at the selected drive location

34

With this last action we are all done with the Source Site “Site001”

Please note that we have performed all the above steps just to simulate a proper business case where someone already created a Workflow and now we need to move it to some other SharePoint Site. In case if you already have a workflow created then you can always skip the steps above

Step 6: Destination Site – Provision Content Type

In order to move the Workflow based on the content type we need to first deploy the Content Type Solution to the Destination Site “Site002”

You should deploy it using PowerShell; in here I am making use of Visual Studio to get it deployed as shown below-

35

36

Once the Content Type Solution deployed successfully we should enable the feature to provision the Content Type

37

In order to verify if the Content Type has been provisioned correctly we should go as follows:

  • Go to Site Settings
  • Click on “Site Content Types” link

38

We can filter the list of available Content Types by “Custom Content Types” Group

And there we can see the “CustomerCT” content type provisioned correctly

39

 

That is all for this demo.

We will be looking for Step 7 & 8 in Part 4 of this Series.

SHAREPOINT 2013 : HOW TO MIGRATE SHAREPOINT 2010 STYLE WORKFLOWS – PART 4

So guys just stay tuned 🙂

 

SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 2

In the first article SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 1 of this series on the Workflow migration Process we saw the execution of Steps 1 & 2 for the process.

In this article we are going to see the execution of Steps 3 & 4 and for the sake of quick review I am putting up the process diagram again in here.

Process Diagram

1

Step 3: Source Site – Create Workflow

  • Launch the SharePoint 2013 Designer
  • Connect to the Source Site “Site001”
  • Click on the Workflows section on the left
  • Click on the “Reusable Workflow” Ribbon Control

9

  •  Specify the Workflow Name “CustomerLogs”
  • Select “CustomerCT” content type that we had provisioned in the earlier steps
  • And since this demo is to show how to export SharePoint 2010 Style Workflows so we should choose the Platform Type as “SharePoint 2010 Workflow”
  • Click OK to save the Workflow

10

We can see the new workflow created under “Reusable Workflow” Category

11

Step 4: Source Site – Test Workflow

Now we have to associate “CustomerLogs” workflow with Content Type “CustomerCT”

To add the association go to Site Settings > Site Content Types

12

Filter the content types by group “Custom Content Types”

We can see the “CustomerCT” Content Type available in the Site Content Types List

Click on “CustomerCT” Content Type and edit it

13

Under Settings section click on the “Work Settings”

14

Click on “Add a Workflow” Link

15

Under the Workflow Section you should see the “CustomerLogs” workflow list in Workflow Template list and specify a suitable name as “Customer Logging” in this case

Save the Workflow Settings

16

Now we can see new instance of “CustomerLogs” workflow associated with “CustomerCT” content type

17Now lets’ create a Test SharePoint List to verify the Workflow is working fine in association with Content Type

  • Go to Site Contents
  • Select “Custom List” list template to create a list

18

Let us call this list as “Customers” and click “Create”

19

We can see the “Customers” List created a successfully

20

Now we need to add “CustomerCT” content type to the “Customers” list

  • Go to List Settings
  • Click on the “Advanced Settings” link

21

  • Select “Yes” under “Content Types” Section
  • Save the settings

22

Click on the “Add from existing content types” link and select the “CustomerCT” content type

23

24

Now create a new item based on “CustomerCT” content type

25

  • Add suitable values to the fields

26Since we did not configured the “CustomerLogs” Workflow to start automatically on “Item Added” or “Item Updated” so we need to manually start it

27

Now lets’ review the workflow status

Click Ellipsis and select “Workflows” to get the Workflow Start Page

28

Click on the “Customer Logging” workflow to start

29

  • Click on “Start” button

30

And we got the workflow started & completed

31

We can verify the Workflow Status and also the message logged by it to the history log

32

That is all for this demo.

We will be looking for Step 5 & 6 in Part 3 of this Series.

SHAREPOINT 2013 : HOW TO MIGRATE SHAREPOINT 2010 STYLE WORKFLOWS – PART 3

So guys just stay tuned 🙂

SharePoint 2013 : How to migrate SharePoint 2010 Style Workflows – Part 1

In this article we are going to learn the steps that are involved in moving SharePoint 2010 style reusable workflows from one site to another and I must say this a bit of tricky process all around.

The whole process of exporting SharePoint 2010 Style Workflow involves 8 steps as showing below in Process flow diagram which I will be going to deliver as a series of four articles-

Process Diagram

1

So we can see that we got to go a long way in order to accomplish the task of moving workflow from one location to another so let’s hit the floor

Step 1: Create Site Collections

In order to setup this demo we need to first create two Sites lets’ call them “Site001” (Source) & “Site002” (Destination)

So the task is to move a reusable SharePoint 2010 Workflow from Source Site to Destination Site.

So we created both Source & Destination Sites as per usual process as shown below:

2

3Step 2: Source Site – Provision Content Type

In order to develop a reusable workflow in the Source site we would be needing a Content Type to be provisioned first based on that we can be able to create the require reusable workflow

In order to provision the Content Type lets create a solution and add a content type based on our business requirements.

Here for the sake of this demo I have added a Content Type called Customers with just two fields “Work Address” & “Company Name”

4

Lets’ name the feature associated with this content type as “Enable Customer Logging”

5

In order to provision the Content Type we need to deploy the solution and activate the “Enable Customer Logging” feature

6

In order to verify if the Content Type is provisioned we can go to Site Settings > Site Content Types

7

Filter the content types by group “Custom Content Types”

We can see the “CustomerCT” Content Type available in the Site Content Types List

8

That is all for this demo.

We will be looking for Step 3 & 4 in Part 2 of this Series.

SHAREPOINT 2013 : HOW TO MIGRATE SHAREPOINT 2010 STYLE WORKFLOWS – PART 2

So guys just stay tuned 🙂

 

Executing Direct SQL Queries on SharePoint Content Databases: Is it a good idea???

This article is based on the findings and lessons learnt during one of my recent assignments which included the development of an Analysis Tool which can gather all Vitals out of a SharePoint Farm which can be further leveraged to take decisions during the migration at some later stage.

While deciding the direct execution of SQL Queries on SharePoint Databases, you should consider the following questions and plan accordingly-

What could be the possible repercussions if we execute direct SQL queries on Content Database?

  • Reading from the SharePoint databases programmatically, or manually, can cause unexpected locking within Microsoft SQL Server which can adversely affect performance.
  • Any read operations against the SharePoint databases that originate from queries, scripts, .dll files (and so on) that are not provided by the Microsoft SharePoint Development Team or by Microsoft SharePoint Support will be considered unsupported if they are identified as a barrier to the resolution of a Microsoft support engagement.
  • If unsupported read operations are identified as a barrier to the resolution of support engagement, the database will be considered to be in an unsupported state.
  • To return the database to a supported state, all unsupported read activities must stop.

What are unsupported operations on SharePoint Content Databases?

It is clearly unsupported to update, delete, or insert records. The risks are surely far more obvious. Also be aware that any database changes would definitely break the supportability as stated by Microsoft. Examples of such database changes include, but are not limited to the following:

  • Adding database triggers
  • Adding new indexes or changing existing indexes within tables
  • Adding, changing, or deleting any primary or foreign key relationships
  • Changing or deleting existing stored procedures
  • Calling existing stored procedures directly, except as described in the SharePoint Protocols documentation
  • Adding new stored procedures
  • Adding, changing, or deleting any data in any table of any of the databases for the products
  • Adding, changing, or deleting any columns in any table of any of the databases for the products
  • Making any modification to the database schema
  • Adding tables to any of the databases for the products
  • Changing the database collation
  • Running DBCC_CHECKDB WITH REPAIR_ALLOW_DATA_LOSS (However, running DBCC_CHECKDB WITH REPAIR_FAST and REPAIR_REBUILD is supported, as these commands only update the indexes of the associated database.)
  • Enabling SQL Server change data capture (CDC)
  • Enabling SQL Server transactional replication
  • Enabling SQL Server merge replication

What are supported operations on SharePoint Databases?

  • Operations that are initiated from the SharePoint administrative user interface
  • SharePoint specific tools and utilities that are provided directly by Microsoft (for example, Ststadm.exe)
  • Changes that are made programmatically through the SharePoint Object Model and that are in compliance with the SharePoint SDK documentation

What happen if unsupported data modification is discovered?

If an unsupported database modification is discovered during a support call, the customer must perform one of the following procedures at a minimum:

  • Perform a database restoration from the last known good backup that did not include the database modifications
  • Roll back all the database modifications

What if previous version of the database that does not include the unsupported modifications is unavailable or if the customer cannot roll back the database modifications?

  • The customer must recover the data manually.
  • The database must be restored to an unmodified state before Microsoft SharePoint Support can provide any data migration assistance.
  • If it is determined that a database change is necessary, a support case should be opened to determine whether a product defect exists and should be addressed.

What can be done if still the content database needs to be queried directly for some reason?

Never run the direct SQL queries on Content Database in Production Environment

Take Following steps:

  • Restore the Database backup from Production to Development Environment
  • Take Database Offline
  • Run SQL Queries with [NOLOCK] option

Before running the above steps make sure the database is not in intermediate stage [nothing is checked out] else can get different document count then actual.

Key Takeaways: Based on the facts exposed by Microsoft Documentation on Direct Query Execution on Content Databases the key takeaways are:

  • This is completely unsupported by the EULA you agreed to when you installed SharePoint.
  • Your queries are not guaranteed to work after applying any patches or service packs to SharePoint since Microsoft could change the database schema anytime.
  • Directly querying the database can place extra load on a server and hence performance issues.
  • Direct SELECT statements against the database take shared read locks at the default transaction level so your custom queries might cause deadlocks and hence stability issues.
  • Your custom queries might lead to incorrect data being retrieved.

How to Get Public Key for SharePoint Projects

Visual Studio Version: 2010

SharePoint Foundation development projects often involve a mixture of imperative coding and XML markup. Frequently, you add your new assembly’s Public Key Token to a project file, such as an XML configuration file.

If your Visual Studio project is based on any of the SharePoint 2010 project templates in Visual Studio, you can simply insert the placeholder $SharePoint.Project.AssemblyPublicKeyToken$ where the Public Key Token should be in most kinds of project files (but not .cs or .vb files or other compilable files).

When you build and deploy the project, Visual Studio will replace the placeholder with the Public Key Token in the copies of the files that are actually deployed.

If you need to insert the Public Key Token in a file that does not support the placeholders, you will need a way to obtain the Public Key Token. This topic explains how to add an item to the Visual Studio Tools menu that can be used to obtain the Public Key Token of an assembly under development.

  • Launch Visual Studio and click on External Tools under Tools Menu as shown below:

1

  • Click on Add button

2

  • Enter Title of your choice
  • Enter Command as the path to sn.exe file, you can find this command line utility at the following location C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\sn.exe
  • Enter Arguments as -T $(TargetPath), this will be replaced by the selected project later on

Make sure “Use Output Window” checkbox is checked so that you can be able to get the Public Key on the Output Window with in Visual Studio.

3

  • Select the project for which you want to find out the Public Key

4

  • Click on Get Public Key under Tools menu

5

  • Public Key Token is now available on the output window

6

That’s so simple yet powerful.

It is really useful for a SharePoint Developer to have these kind of tools handy.

Hope this will help someone in need…

SharePoint 2010: How to Read SharePoint List using SharePoint REST API and JSON

In this article we will see how JSON can be leveraged to access the SharePoint Lists using SharePoint REST API.

In order to execute this article we would need a SharePoint List which can be accessed using REST API later on.

For this demonstration we have a list by the name “LOB”, with one of the list columns by the name “LOB”.

1

The next step is to visit the Project Structure for this demonstration.

Project Structure:

2

Based on the above project structure following are required artifacts to be developed in order to see JSON in action:

  • SharePoint Mapped Folder: GetSharePointListInJASON
  • Application Page : SharePointListInJASON.aspx

In order to develop this functionality we need to add the Application Page which will contain the logic to access SharePoint List using REST API and JSON.

3

Definition of SharePointListInJASON.aspx

First of all we need to create a link which on click triggers the function “getListItems”.

4

Now let’s dive deep into the execution of getListItems function.

getListItems function executes as follows:

  • Specify the valid Url calling the REST Service
  • Create a WebRequest Object using ASP.Net 3.5 Ajax API
  • Specify the Request Type, in this case it is GET
  • Specify the Accept Header which defines the data format of the Response, in this case it is JSON
  • Specify the Callback function which will be executed by the runtime once the request is completed

onCompletedCallBack call back function executes as follows:

  • Parse the JSON response into a set of objects by using the JavaScript eval() function
  • Loop through the object to retrieve the required values
  • Prepare Html markup based on the retrieved values and display it on the page.

5

And we are done.

Now build the solution and deploy it.

Navigate to the SharePointListInJASON.aspx Application Page which resides under layout directory in SharePoint Root (14 Hive) as shown below:

6

Click the link and see the list items coming as a part of the response.

7

Now let’s do some investigation on some of the internals of this asynchronous service call by using a Web Proxy Tool known as Fiddler:

If we follow the Fiddler, we can see traffic capture for this asynchronous service call as shown below:

8

If we inspect the different attributes of this request we find the following important information about this asynchronous service call:

9

If we inspect the response object, we will find the incoming JSON structure as follows, this information is very important to understand how to use the response the response object in code. Properties exposed by the response object are highlighted as follows:

10

That’s the end of this simple implementation employing SharePoint Rest API and JSON.

Hope this will help someone in need…

SharePoint 2010: Delegate Controls in Action

We can following noteworthy points on Delegate Controls in SharePoint:

  • SharePoint provides a mechanism that allows developers to customize out-of-the-box functionality in pages, without the need for modifying the pages that come with SharePoint. This mechanism is provided with delegate controls.
  • A delegate control defines a region in an aspx page that allows the content to be replaced with our custom content. This custom content is created via a SharePoint feature, and when deployed and activated, replaces the standard content at runtime.
  • By declaring a control as an element in a Feature and giving it a priority through the Sequence attribute of the Control element, SharePoint selects the declared control candidate and instantiates it as a child of the delegate control. At run time, this delegate control accepts the union of control elements declared at the server farm, Web application, site collection, and Web site levels.
  • The control that has the lowest sequence number is added to the control tree through the DelegateControl.
  • Delegate controls for which the AllowMultipleControls property equals true can host more than one child control.
  • If there are multiple delegate control candidates, they are all added as children at runtime in the order specified by the Sequence attribute. For example, by default the AllowMultipleControls property is used in the AdditionalPageHead delegate control to allow multiple child controls to be added to any page that contains the delegate control.

Now let see the delegate control in action.

In this article we will see the steps involved in replacing the SharePoint global navigation with Control ID “GlobalNavigation”. We will discuss the significance of this Control ID attribute in detail later in this article.

Project Structure:

1

Based on the above project structure following are required artifacts to be developed in order to get the delegate control working:

  • Custom Control   :          GlobalNavigation.ascx
  • Module                :          GlobalNavigation
  • Web Scoped Feature :  CustomDelegateControl

Custom Control: First of all we need to create a custom control that will be used to replace the existing SharePoint Delegate Control.

Definition of GlobalNavigation.ascx

2

GlobalNvaigation.ascx file contains the UI logic for the delegate control, in this case this is simply declaring a label control that will contains the urls of all lists in current site.

Definition of GlobalNavigation.ascx.cs

3

GlobalNavigation.ascx.cs file contains the logic to display all the lists from current site.

Element.xml

4

The information in Element.xml file is very important to understand, as this information tells SharePoint which Delegate Control needs to be replaced.

  • Id Attribute contains the value of the OOB SharePoint Delegate Control, make sure you specify correct value, else this won’t work.
  • Sequence Attribute contains the value of the sequence in the control tree, make sure this value is less than the sequence value for OOB SharePoint Delegate Control else OOB SharePoint Delegate Control won’t get replaced by the custom control.
  • ControlSrc Attribute contains the path of the custom control relative to the ControlTemplates Directory under SharePoint Root Folder (14 Hive).

Web Scoped Feature:

5

Now we are done with all the deployable, and it’s time to create a feature which will deploy the artifacts in SharePoint Farm.

We need to create a Web Scoped feature, which allows us to activate this Global Navigation Control on the specific sites instead of the complete site collection, though this can be designed based on the business requirements.

Now build the solution and deploy.

Final Output:

6

And we are good to go.

Hope this will help someone in need…

SharePoint 2010: Connected Web Parts in action

Connected WebParts are best suited for the scenarios where data communication between two WebParts is required at run time.

Following are the most basic steps involves in the development of Connected Web Parts:

Step1 : Creating WebPart connection interface

Step2 : Creating Provider WebPart using WebPart Project Item

Step3 : Creating Consumer WebPart using WebPart Project Item

Now lets see the connected WebPart in action.

  • Create Empty SharePoint Project

1

2

  • Creating WebPart connection interface : Add a class file which contains the definition of the interface.

3

  • Interface Definition

4

  • Creating Provider WebPart using WebPart Project Item : Add new project item based on WebPart project item type

5

6

  • Provider.cs: This file implements the business logic for Provider WebPart. This class will implement ConnectionProvider Property

78

  • Element.xml: This file will expose the deployment information of Provider WebPart to SharePoint

9

  • Creating Consumer WebPart using WebPart Project Item

10

11

  • Consumer.cs: This file implements the business logic for Provider WebPart. This class will implement ConnectionConsumer Property

1213

  • Element.xml: This file will expose the deployment information of Consumer WebPart to SharePoint
  • Creating Site Level Feature for the deployment of connected WebParts

14.1

  • Build and Deploy solution
  • Test Connected WebParts
  •      Create a new WebPart Page

15

16

17

  •      Add Provider and Consumer WebParts on the WebPart Page

18

  •     Create connection between Provider and Consumer WebParts

19

20

  •    Enter string in the Provider WebPart and click Send Button, the string value is transferred to the Consumer WebPart using connection between Provider and Consumer WebPart.

21

  •  Value transferred to Consumer WebPart on button click.

22

Hope this will help someone in need…