Monday, August 19, 2013

Add data to people picker in Visual webpart programatically - sharepoint 2010

Add the People picker field in the ascx file as below

 <SharePoint:PeopleEditor runat="server" ID="peoplePickerID" MultiSelect="true" 
SelectionSet="User" />

in the code behind on page load write the logic to fill teh people picker from a list having a
people/group type column.


ArrayList PickerEntities = new ArrayList(); 
SPFieldUserValueCollection fieldUserValueCollection = (SPFieldUserValueCollection)item["PeopleGroupTypeColumnDispName"];

            foreach (SPFieldUserValue spuserval in fieldUserValueCollection)
            {
                SPUser userToassign = spuserval.User;
                PickerEntity entity = new PickerEntity();
                PeopleEditor pepEditor = new PeopleEditor();
                entity.EntityData["AccountName"] = spuserval.User.LoginName;
                entity.EntityData["SPUserID"] = spuserval.User.ID;
                entity.EntityData["Email"] = spuserval.User.Email;
                entity.Key = spuserval.User.LoginName;
                entity.Description = spuserval.User.LoginName;
                entity.DisplayText = spuserval.User.Name;
                entity = pepEditor.ValidateEntity(entity);
                entity.IsResolved = true;
                PickerEntities.Add(entity);
            }

peoplePickerID.UpdateEntities(PickerEntities);

 *item["PeopleGroupTypeColumnDispName"];--> is list column of people/group type


Have a look at other post about client people picker of Sharepoint 2013
Client people picker-Sharepoint 2013 



 

Wednesday, August 7, 2013

SharePoint 2013 Workflow

The concept of Workflow in SharePoint 2013 is changed a whole lot.

The three thing which you need to take care while configuring the workflow to run on SharePoint 2013 is that

  1. Workflow Manager 1.0
  2. Workflow client 1.0
  3. Workflow Manager Tool for Visual 2012
  4. Developer Tools for Visual studio.

As the Workflow does not run inside the share point  you can install Workflow Manager 1.0  on different server or on same server where share point is hosted ..You can follow the MSDN link below to install and configure the Workflow Manager 1.0.

http://technet.microsoft.com/en-us/library/jj658588.aspx

Workflow client 1.0 - This has to be installed on all the sharepoint server (Web fornt end,App).This has API which communicates with the Workflow Manager.

Workflow Manager Tool for Visual 2012 - This has to be installed on the server where you create Visual studio 2013 SharePoint Workflow.Assuming that VS2012 is already installed .
2013 Sharepoint WF template is named as "Workflow"  in VS the "sequential and state machine" template is legacy now and it is not used in SharePoint 2013.

Developer Tools for Visual studio- Is to be installed on server where the Visual studio 2012 is installed.This provide new activities in Tool Box of VS12.


Along with this when you try to install the WorkflowManager through webPlatform installer .
Service Bus and cummunlative updates will be installed automatically.If you are installing it manually you need to install all the updates and Service bus.


Even after having all this there will be few problem with sending mails from VS12 WF.To overcome the issue You need to Install the MARCH-PU sharepoint 2013 updated and configure the same.


Plese follow the below link to install and configure it

http://www.deliveron.com/blog/post/Installing-March-2013-Public-Update-on-SharePoint-Server-2013.aspx


After all these are done you also need
  • App Management Service to be running
  • User Profile Service to be running
  • User Profile Sync Service to be running
Only then your WF runs without any problem :)

Tuesday, July 30, 2013

Add data from People Picker control into people/Group column field of a list in Sharepoint Visual Webpart

The below code can be used in visual webpart where in you have a requirement to pick the data from people picker field and add the data to people or group column of any list


 SPFieldUserValueCollection customer = new SPFieldUserValueCollection();
                    foreach (PickerEntity enity in pepPickCustomer.ResolvedEntities)
                    {
                        SPUser user = SPContext.Current.Site.RootWeb.EnsureUser(enity.Key);
                       
customer .Add(new SPFieldUserValue(SPContext.Current.Site.RootWeb, user.ID, user.Name));

                    }

Later to add data to list

item["PeopleGroupColumName"] = customer;


*
pepPickCustomer is the ID of Client people picker control which is a new type of people picker control available Sharepoin 2013.

Thursday, July 25, 2013

Run all Powershell Scripts through batch file (.dat)

If you have many powershell scripts and you want to run all of those in a single click deployment
then use the below technique


1)Create a batch file  named "StartFile.bat"
2)Create a powershell script "PowershellFile.ps1" and add all your code in it
3)Edit the "StartFile.bat" and add the below piece of code



cd /d %~dp0
powershell.exe -File
PowershellFile.ps1
pause


4)Now save the changes
5)Run the batch file as Admin.
6)Your powershell script will be run



------------------------------------------------------------------------------------------------------------cd /d %~dp0
will open the powershell.exe from current location where the whole folder consisting of batch and powershell file is placed in a folder.

Friday, July 5, 2013

Add data to People picker field programatically -Sharepoint 2013

I had a requirement where in the visual webpart had a people picker control .I used the client people picker which is a new and betta control in Sharepoint 2013.This control had to be binded with the data coming from a people picker field of some list.Here is the code to achieve it




SPFieldUserValueCollection reviewers = (SPFieldUserValueCollection)Item["PeoplePickerFieldColumnDisplayName"];
List<PickerEntity> reviewersEntity = new List<PickerEntity>();
foreach (SPFieldUserValue spuserval in reviewers){

SPUser userToassign = spuserval.User;
PickerEntity entity = new PickerEntity();
PeopleEditor pe = new PeopleEditor();
entity.EntityData["AccountName"] = spuserval.User.LoginName;
entity.EntityData["SPUserID"] = spuserval.User.ID;
entity.EntityData["Email"] = spuserval.User.Email;
entity.Key = spuserval.User.LoginName;
entity.Description = spuserval.User.LoginName;
entity.DisplayText = spuserval.User.Name;
entity = pe.ValidateEntity(entity);
entity.IsResolved =true;
 reviewersEntity.Add(entity);
}
PeoplePickerControlName.AddEntities(reviewersEntity);



*"item " is a SPListItem type


in ascx file client people picker looks like

<SharePoint:ClientPeoplePicker runat="server" ID="PeoplePickerControlName" Required="true" ValidationEnabled="true"
                        InitialHelpText="text"
                        VisibleSuggestions="3"
                        Rows="1"
                        AllowMultipleEntities="true"
                        CssClass="ms-long ms-spellcheck-true" /> 

Have a look at other post about  people picker of Sharepoint 2010
People Picker -Sharepoint 2010