SharePoint Developer Support Team Blog

The Official blog of the SharePoint Developer Support Team

August, 2013

  • HOW TO: Add users to SharePoint Groups using SharePoint 2013 UserGroup.asmx Web Service

    This post is a contribution from Raghavendra B Nanjaiah, an engineer with the SharePoint Developer Support team.

    Problem

    When you try to add users through the UserGroup.asmx web service (http://localhost/_vti_bin/UserGroup.asmx) in SharePoint 2013 with the sample code below.

    sp.UserGroup usrgrpService = new sp.UserGroup();
    usrgrpService.Credentials = new System.Net.NetworkCredential("Administrator", "access", "contoso");
     
    usrgrpService.AddUserToGroup("Dev Members", "usera",
    "contoso\\usera", "usera@contoso.com", "Notes");

    You will successfully add user to the SharePoint group, but if you look at the user permission or try accessing site using this user credentials, you’ll get “Site is not shared with you” message.

    Solution

    You have to pass user in claims encoded format (e.g., i:0#.w|contoso\chris) in SharePoint 2013.  This is because claims authentication is enabled in the web applications you create by default.

    Not that this is something that many don’t know, but we’ve had customers reporting this issue to us and we thought we’ll get this message out!

    HTH

  • HOW TO: Develop a workflow code activity in SharePoint 2013

    This post is a contribution from Raghavendra B Nanjaiah, an engineer with the SharePoint Developer Support team.

    First part is to create our code activity and let the Workflow Manager and SharePoint 2013 know about it.

    1. In VS 2012, click New Project, Workflow and choose Activity Library.

    image

    2. Delete the declarative Activity1.xaml from the solution since we will be creating our own custom code activity.

    3. In solution explorer on newly created activity library right click and select add new item -> Workflow -> Code Activity.

    image

    4. Decide what data you would like to pass in to custom activity. In my case I am accepting string as InArgument and trying to create new list item based on the input string parameter  (you can also use OutArgument which represents the flow of data out of an activity).

    image

    5. Write your activity logic in overridden execute method.

    6. Build the Project and sign the code activity assembly.

    7. Now, Create a new xml file and name it as AllowedTypes.xml and add the reference of you activity library dll , Namespace and type as shown below ( this basically adds your assembly to whitelist which Workflow service trust and loads. If your assembly is not in whitelist you might receive activity not found exception)

    image

    8. Now it's time to deploy our assembly and allowedtypes.xml to the folder from where Workflow manager and SharePoint can read.

    * On the Workflow Manager box you have to:

         - Copy activity assembly to following locations:

              > %ProgramFiles%\Workflow Manager\1.0\Workflow\Artifacts

              > %ProgramFiles%\Workflow Manager\1.0\Workflow\WFWebRoot\bin

         - Add your activity class to the white-list

              > Copy AllowedTypes.xml  also to above two locations

         - Restart “Workflow Manager backend” service

    * On SharePoint box you have to:

         - Copy activity assembly to SharePoint box and install it in the GAC.

         - Reset IIS

     

    Now, the second part is to create a workflow using custom code activity that we created by following the above steps.

    1. Now in the same visual studio solution where you have custom code activity add new SharePoint 2013 Workflow project.

    2. From the toolbox drag and drop the custom code activity that we just developed.

    image

    3. Right click and deploy the solution to your SharePoint site.

     

    Bingo! Now we have developed and deployed custom code activity Workflow in SharePoint 2013 with Workflow Manager 1.0. Smile

    Hope this helps!