Monday, 25 November 2013

Creating a simple Event Receiver in SharePoint 2013

Create an empty SharePoint 2013 project in Visual Studio 2012. In the project, select add new item and select Event Receiver

Select the type of event receiver you need to add, and select the events you need to handle.

 Here, I have created the Department library to add and maintain documents and also created DocumentLog list to log the changes happening to the library.



In the list I have three columns, Title, Action & DateAndTime in order to catalog the changes happening to the library.
 
Back to the SharePoint project. Now go to the event receiver .cs file and you'll get a bunch of methods base on your selection during event receiver creation. Edit the code as below to implement the logic. Note that the ItemAdded method is used instead of the ItemAdding method.
 
public override void ItemAdded(SPItemEventProperties properties)
        {
            //base.ItemAdded(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Added";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

public override void ItemUpdating(SPItemEventProperties properties)
        {
            //base.ItemUpdating(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Updated";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }

public override void ItemDeleting(SPItemEventProperties properties)
        {
            //base.ItemDeleting(properties);
            using (SPWeb web = properties.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists["DocumentLog"];
                    SPListItem newItem = list.Items.Add();
                    newItem["Title"] = properties.ListItem.Name;
                    newItem["DateAndTime"] = System.DateTime.Now;
                    newItem["Action"] = "Item Deleted";
                    newItem.Update();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }






Thursday, 14 November 2013

'Login failed for user 'NT AUTHORITY\IUSR'

Message from ExternalSystem: ‘Login failed for user ‘NT AUTHORITY\IUSR’.’.





 This error occurs because database does recognize the credentials passed from SharePoint. Which database? Database that you are connecting to in your external content type! It depends on you have setup application pool identity in SharePoint. If you are not using managed service account for your services, you are most likely to get this error. This is not likely to occur in corporate environments but in home or test environments where users use LOCAL SYSTEM OR NETWORK SERVICE in application pools, this error will occur. This is because NETWORKSERVICE translates to NTAUTHORITY\IUSR when credentials are passed from web server to database server. IUSR is used when user credentials are not available, for example, for anonymous users. To resolve this problem, either change application pool identity or add NT AUTHORITY\IUSR to the database permissions. The first scenario is quite common. You can change application pool identity by go to the web server and updating application pools or by logging into SharePoint central admin site and going to ManageService Accounts. We will cover second scenario here, that is, to add IUSR to the database.


1.      Go to MicrosoftSQL Server Management Studio and connect to your database server.


2.      Expand Security node and right-click Logins node and select New Login.






3.      In the LoginName, enter IUSR and click Search…. This will open a new search box. Enter IUSR in the object name and click Check Names. Click OK.


4.      You will notice that Login Name has been populated with MACHINENAME\IUSR where MACHINENAME is your machine name, for example, in the figure below, you see SP2013\IUSR. SP2013 is my machine name.




This is not what you want to add to the logins. Change MACHINENAME to NT AUTHORITY so Login Name should read NT AUTHORITY\IUSR. Click OK.


5.      Now you may think that the user has been added and your external content type will work. Right? Wrong! You still have to map user to the database otherwise you will get following error on the list page(where you are trying to load external content type):


The query against the database caused an error.






 
 





 

This error occurs, as I said, because user is not mapped to the database yet.


6.      To map user to the database, right-click NT AUTHORITY\IUSR in Logins and select Properties.





 
 




7.      There are two ways to do this mapping. One way is to add user to one of the server roles, for example,  serveradminor sysadmin. This will give user full rights to all databases and thus you won’t have to do explicit mapping. To do this, on the properties page, click ServerRoles and check sysadmin. Click OK. Obviously you would not want to do this in real environment. So the other option is to map the user directly to the database that has been used in the external content type.






To add user mapping, in LoginProperties, click User Mapping. Locate the database in the list and then check the box in the Map column. As soon as you check the box, NT AUTHORITY\IUSER appears in the User column. That’s it. Click OK to save the setting. By the way on the same properties page, you can also assign database role membership to the user for the database but that is not required.






Now, go back to the list page and reload it. You will see results from the external data source.
 
 

Saturday, 19 October 2013

Sample user agent substring values -- Device channels


For Chrome

1. Name  = Chrome
   Alais = Chrome
   Description = Chrome desc
   Device Inclusion Rules = Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
  Active = true

For Internet Explorer 10

2. Name = Internet Explorer 10
   Alais = Ie10
   Description = This channel for Internet explorer 10
   Device Inclusion Rules = compatible for ie 10
   Active = true

3. Windows Phone
  • 1. Device Inclusion Rules = Windows Phone OS 7.5 (Specific to Windows Phone 7.5 phone.
  • 2. Device Inclusion Rules = Windows Phone OS (Generic substring for all Windows Phone versions.)
4. iPhone
Device Inclusion Rules = iPhone

5. iPad
Device Inclusion Rules = iPad

6.Android
Device Inclusion Rules = Android



 

Tuesday, 8 October 2013

How to Use and Configure Device Channels

Add Html Master page to a SharePoint 2013 using Design Manager

 Design Manager in SPS 2013 is a new feature. It can be very useful for SharePoint Designers. With the Design Manager, You can now create a SharePoint Master page out of simple Html page Template that can be reuse from an existing public site or download from internet.
Follow this example, How to convert an Html template into SharePoint Master Page using the Design Manger and Snippet Gallery. If you want to edit an existing Master page head over to How to edit an existing master page to change logo, hide top suit links etc in SharePoint 2013.


Before we begin, make sure you have your Html template ready. A good option is to download from internet - In our case we download from Templatesbox.com a web site that  provides free Html templates along with images.

Once you have your templates and images Upload the entire folder in the master page gallery. Easiest way to do this is to Map your Master page Gallery as a net work drive and copy the folder in it.

Hear is the master page that we will use.












 




 

SharePoint 2013 Design Manager

Introduction

The Design Manager is a new tool in SharePoint 2013. It’s available when you use the Publishing Portal site template or activate the Publishing Infrastructure feature at the site collection level. The Design Manager is a new option in the Look and Feel section of the Site Settings.
SharePoint Site Collection Feature

 


Device Manger Options

Design Manager

This Feature available in the Publishing site Portal or the site having both infrastructures publishing feature activated at Site and web level. The Design Manager is a new option in the Look and Feel section of the Site Settings.
 



Friday, 13 September 2013

Register-SPWorkflowService –SPSite Error

Register-SPWorkflowService –SPSite Error

Register-SPWorkflowService –SPSite “http://c4968397007/” –WorkflowHostUri “https://c4968397007:12290″ –AllowOAuthHttp

If the above script getting the error, then

1. Open the IIS manager in SharePoint Server
2. Expand Sites
3. Right click on Workflow Management Site, Click on Edit Bindings, Click on Add, Enter the Port as 12291 and click on ok.



4. Now browse the Workflow Management Site.
5. Now the the above script as follows

Register-SPWorkflowService –SPSite “http://c4968397007/” –WorkflowHostUri “http://c4968397007:12291″ –AllowOAuthHttp

It will be executed now


Thursday, 12 September 2013

Configure Workflow Manager On Server is a Part of the SharePoint 2013

Configure Workflow Manager On Server is a Part of the SharePoint 2013

Workflow infrastructure in SharePoint 2013 is not set up as part of the installation process of the platform. You can install WAS in an independent server or in a web frontend server after you have installed SharePoint 2013.

We have two options to install Workflow infrastructure for SharePoint 2013:
 
1. Use the Web Platform Installer available at:
http://www.microsoft.com/web/downloads/platform.aspx
 
2. Download and install the workflow individual components from
http://www.microsoft.com/en-us/download/details.aspx?id=35375

Installing Workflow Manager 1.0
To simplify the workflow infrastructure setup, we are going to use the Web Platform Installer option explained above:
  • Download the installer from the web and execute it.
  • In the “Spootlight” tab of the Web Platform Installer, look for the SharePoint workflow components by using the sesrch box.
  • In the search results, click the “Add” button for the Workflow Manager 1.0 row. Then, click the “Install” button.
image
  • The installation process will install Workflow Manager 1.0 and configure all the necessary dependencies:
    • Execute ASP.NET IIS Registration Tool.
    • IIS Management Service.
    • Service Bus 1.0.
    • Microsoft Windows Fabric.
  • In order to start the installation process, just click the “I accept” button in the wizard.
image
  • Once the installation process ends, you can start with the configuration as it’s described in the “Configure” step tab of the wizard. Click the “Continue” button so the wizard shows a summary window with all the components installed and configured.
image
Configuring Workflow Manager 1.0
Once you have installed Workflow Manager 1.0, a configuration window wizard is started:
  • As you can see, there are three possibilities for configuring the Workflow Manager. Just click the first one:
image
  • In the first configuration window of the wizard, you have to specify parameters like:
    • SQL Server where all the needed databases will be created.
    • Service account.
    • Key for certificates generation.
image
  • Click the “Next” button in order to start the configuration. In the next window, check that all configurations are right and press the “Configuration” button.
image
  • If everything is correct with the configuration, the next window will confirm that all configurations are complete without any errors or warnings.
image
Testing the installation
Well, once you have finished the configuration process you should verify that everything is right:
  • Some databases (5) have been created. You can check databases created by using the SQL Server Management Studio.
image
  • A new IIS site for workflow management has been created. You can check it by using the IIS Manager.
image
  • The workflow service endpoint (by means of the site created) is ready to be utilized. You can check it by browsing the Workflow Management Site from IIS Manager.
image
Associating the workflow service with an existing Site Collection
Well, you are almost done and only need one additional configuration step in order to start creating and deploying SharePoint 2013 workflows: you need register the workflow service with an existing site collection by using the following Register-SPWorkflowService cmdlet. Execute it in the SharePoint 2013 Management Shell. Please ensure you use the following syntax:
Register-SPWorkflowService –SPSite “http://c4968397007/” –WorkflowHostUri “https://c4968397007:12290″ –AllowOAuthHttp
[ Note : The above script unable to execute using the URI as Https   Then Click on this link how to do http://www.blogger.com/blogger.g?blogID=3840435550659422660#editor/target=post;postID=4742666287090848379;onPublishedMenu=posts;onClosedMenu=posts;postNum=0;src=postname  ]
Finally, open SharePoint Designer 2013 and check you can create SharePoint 2013 workflows Sonrisa
image
And that’s all you need to know about how to setup the workflow infrastructure for SharePoint 2013.