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.

Advertisements

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…