Friday, May 27, 2016

Adding new item with plus in circle using Content Editor webpart

Adding new item with hyperlink like in the list form using content editor webpart.



Add the following content in the text file and call this text file in content editor webpart

<div align="right">

<table cellspacing="0" cellpadding="0" border="0" dir="none" id="Hero-WPQ2">
<tbody><tr><td class="ms-list-addnew ms-textXLarge ms-list-addnew-aligntop ms-soften">
<a title="Add a new item to this list or library." target="_self"    href="/MOM/Lists/MOM/NewForm.aspx" class="ms-heroCommandLink" id="idHomePageNewItem">
<span class="icon icon-add-new"></span>
<span>Add new MOM </span></a>
</td></tr></tbody></table>

</div>


<style>

/* css example with custom class */
/* img tag technique */


/* background technique */

.icon {
display: inline-block;
overflow: hidden;
vertical-align: middle;
}

.icon-add-new {
width: 22px;
height: 21px;
background: url('/_layouts/15/images/spcommon.png?rev=23') no-repeat -130px -134px;
}

</style>

Ref: 
http://ericoverfield.com/sharepoint-2013-spcommon-png-sprite-breakdown/
https://gist.github.com/empo/6380de9a10710646fd62

Tuesday, May 03, 2016

SharePoint 2013 : People Editor Control SharePoint:PeopleEditor Vs SharePoint:ClientPeoplePicker in Server Object Model

Searched for difference between People Editor Control SharePoint:PeopleEditor  Vs SharePoint:ClientPeoplePicker in SharePoint 2013 Server Object Model

Requirement: Need to add Users and SPGroup using server object model through Visual Webpart.
Googled and find the below code snippet from different site and consolidate below, May be useful to someone. 

Using SharePoint:PeopleEditor control ( Supports SharePoint Version 2010 and 2013)

ASCX File
<SharePoint:PeopleEditor ID="pplCC" runat="server" class="ms-authoringcontrols" SelectionSet="User,SPGroup"   />

Code File

Setting Values to the Control from the list item
SPFieldUserValueCollection userCol = new SPFieldUserValueCollection(SPContext.Current.Web, item["Attendees"].ToString());

SetUserCollectionWithPeopleEditor(pplCC, userCol);


//set People editor control with the SP user collection
        public void SetUserCollectionWithPeopleEditor(PeopleEditor editor, SPFieldUserValueCollection userCollection)
        {
            System.Collections.ArrayList userList = new System.Collections.ArrayList();
            if (null != userCollection)
            {
                foreach (SPFieldUserValue user in userCollection)
                {
                    PickerEntity tempEntity = new PickerEntity();

                    if (user.User != null)
                    {
                        tempEntity.Key = user.User.LoginName;
                    }
                    else
                    {
                        tempEntity.Key = user.LookupValue;
                    }
                    userList.Add(tempEntity);
                }
                editor.UpdateEntities(userList);
            }
        }
                           
Add or Update Values from Control to the list
if (pplCC.Accounts.Count > 0)
                        {
                            oSPListItem["Attendees"] = GetPeople(pplCC, web);
                            // GetUsersFomPeoplePicker("", web, pplCC);
                        }

//set values People editor control
private SPFieldUserValueCollection GetPeople(PeopleEditor people, SPWeb web)
        {
            SPFieldUserValueCollection values = new SPFieldUserValueCollection();
            if (people.ResolvedEntities.Count > 0)
            {
                for (int counter = 0; counter < people.ResolvedEntities.Count; counter++)
                {


                    PickerEntity user = (PickerEntity)people.ResolvedEntities[counter];
                    switch ((string)user.EntityData["PrincipalType"])
                    {
                        case "User":
                            SPUser spUser = web.EnsureUser(user.Key);
                            SPFieldUserValue userValue = new SPFieldUserValue(web, spUser.ID, spUser.Name);
                            values.Add(userValue);
                            break;

                        case "SharePointGroup":
                            SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
                            SPFieldUserValue groupValue = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
                            values.Add(groupValue);
                            break;
                        default:
                            SPUser webUser = web.EnsureUser(user.Key);
                            SPFieldUserValue spuserValue = new SPFieldUserValue(web, webUser.ID, webUser.Name);
                            values.Add(spuserValue);
                            break;
                    }
                }
            }
            return values;
        }



Using SharePoint: ClientPeoplePicker control ( Supports only in SharePoint 2013)

ASCX File
            <SharePoint:ClientPeoplePicker
        Required="true"
        ValidationEnabled="true"
        ID="pplPickerSiteRequestor"
        UseLocalSuggestionCache="true"
        PrincipalAccountType="User,SPGroup"
        runat="server"
        VisibleSuggestions="3"
        Rows="3"
        AllowMultipleEntities="true"
        CssClass="ms-long ms-spellcheck-true user-block"
        ErrorMessage="*"
/>


Code File

Setting Values to the Control from the list item
    SPFieldUserValueCollection userCol = new SPFieldUserValueCollection(SPContext.Current.Web, item["Attendees"].ToString());
                            SetUserCollectionWithPeopleEditorCLIENT(pplPickerSiteRequestor, userCol);

//set People editor control along with the SP user collection to update the list
public void SetUserCollectionWithPeopleEditorCLIENT(ClientPeoplePicker editor, SPFieldUserValueCollection userCollection)
        {
                        
            System.Collections.ArrayList userList = new System.Collections.ArrayList();
            if (null != userCollection)
            {
                foreach (SPFieldUserValue user in userCollection)
                {
                    PeopleEditor pe = new PeopleEditor();
                    PickerEntity tempEntity = new PickerEntity();

                    if (user.User != null)
                    {
                        tempEntity.Key = user.User.LoginName;
                        tempEntity = pe.ValidateEntity(tempEntity);
                    }
                    else
                    {
                        tempEntity.Key = user.LookupValue;
                    }
                    userList.Add(tempEntity);
                    editor.AddEntities(new List<PickerEntity> { tempEntity });
                }
              
            }
        }

Add or Update Values from Control to the list
//FOR UPDATE client people editor
if (pplPickerSiteRequestor.ResolvedEntities.Count > 0)
{

oSPListItem["Attendees"] = GetPeopleCLIENT(pplPickerSiteRequestor, web);

}

//set People editor control along with the SP user collection to update the list
private SPFieldUserValueCollection GetPeopleCLIENT(ClientPeoplePicker people, SPWeb web)
        {
            SPFieldUserValueCollection values = new SPFieldUserValueCollection();
            if (people.ResolvedEntities.Count > 0)
            {
                for (int counter = 0; counter < people.ResolvedEntities.Count; counter++)
                {
                    
                    PickerEntity user = (PickerEntity)people.ResolvedEntities[counter];
                    switch ((string)user.EntityData["PrincipalType"])
                    {
                        case "User":
                            SPUser spUser = web.EnsureUser(user.Key);
                            SPFieldUserValue userValue = new SPFieldUserValue(web, spUser.ID, spUser.Name);
                            values.Add(userValue);
                            break;

                        case "SharePointGroup":
                            SPGroup siteGroup = web.SiteGroups[user.EntityData["AccountName"].ToString()];
                            SPFieldUserValue groupValue = new SPFieldUserValue(web, siteGroup.ID, siteGroup.Name);
                            values.Add(groupValue);
                            break;
                        default:
                            SPUser webUser = web.EnsureUser(user.Key);
                            SPFieldUserValue spuserValue = new SPFieldUserValue(web, webUser.ID, webUser.Name);
                            values.Add(spuserValue);
                            break;
                    }
                }
            }
            return values;

        }

Many thanks to all who shared the knowledge.

Tuesday, March 11, 2014

Out of the Box Web Services in SharePoint

Out of the Box Web Services in SharePoint
There are a number of web services implemented OOTB (out of the box) in SharePoint that will address most of the common and basic tasks, from administrative tasks to search and working with list data, and much more. Below is a listing of the SharePoint web services with an overview of the functionality exposed for your reference. A simple expanded list like this helps me in working with the web services giving me a quick view of the overall services and methods available.
Service
Administration
(_vti_adm/Admin.asmx)
Administrative methods for creating deleting sites and retrieving languages used in the deployment
  • CreateSite
  • DeleteSite
  • GetLanguage
  • RefreshConfigCache
Alerts (Alerts.asmx)
Methods for working with SharePoint list item alerts
  • DeleteAlerts
  • GetAlerts
Authentication (Authentication.asmx)
Client proxy that provides user authentication for sites that use forms-based authentication
  • Login (Used to authenticate)
  • Mode (Returns the authentication mode of the current site)
Copy (Copy.asmx)
Methods to copy files between or within sites
  • CopyIntoItems (Copy document as byte array to location on server)
  • CopyIntoItemsLocal (Copy document from one location on the same server to another)
  • GetItem (Creates a byte array of a document that can be passed to theCopyIntoItems method)
Document Workspace (Dws.asmx)
Methods for managing Document Workspace sites and data
  • CanCreateDwsUrl
  • CreateDws
  • CreateFolder
  • FindDwsDoc
  • GetDwsData
  • GetDwsMetaData
  • RemoveDwsUser
  • RenameDws
  • UpdateDwsData
Forms (Forms.asmx)
Methods for returning forms that are used in the user interface when working with the contents of a list
  • GetForm
  • GetFormCollection
Imaging (Imaging.asmx)
Methods to create and manager picture libraries
  • CheckSubwebAndList
  • CreateNewFolder
  • Delete
  • Download
  • Edit
  • GetItemsByIds
  • GetItemsXMLData
  • GetListItems
  • ListPictureLibrary
  • Rename
  • Upload
List Data Retrieval (DspSts.asmx)
Perform queries against sites and list in SharePoint
  • Query (Performs queries against SharePoint lists and sites)
Lists (Lists.asmx)
Methods for working with Lists and List Data
  • AddAttachment
  • AddDiscussionBoardItem
  • AddList
  • AddListFromFeature
  • ApplyContentTypeToList
  • DeleteAttachment
  • DeleteContentType
  • DeleteContentTypeXmlDocument
  • DeleteList
  • GetAttachmentCollection
  • GetList
  • GetListAndView
  • GetListCollection
  • GetListContentType
  • GetListContentTypes
  • GetListItemChanges
  • GetListItemChangesSinceToken
  • GetListItems
  • GetVersionCollection
  • UndoCheckout
  • UpdateContentType
  • UpdateContentTypesXmlDocument
  • UpdateContentTypeXmlDocument
  • UpdateList
  • UpdateListItems
Meetings(Meetings.asmx)
Create and manage Meeting Workspace Sites
  • AddMeeting
  • AddMeetingFromICal
  • CreateWorkspace
  • DeleteWorkspace
  • GetMeetingInformation
  • GetMeetingWorkspaces
  • RemoveMeeting
  • RestoreMeeting
  • SetAttendeeResponse
  • SetWorkspaceTitle
  • UpdateMeeting
  • UpdateMeetingFromICal
People(People.asmx)
Resolve and find Principals
  • ResolvePrincipals
Permissions (Permissions.asmx)
Methods for working with permissions for a site or list
  • AddPermission
  • AddPermissionCollection
  • GetPermissionCollection
  • RemovePermission
  • RemovePermissionCollection
  • UpdatePermission
Directory Management(sharepointemailws.asmx)
Methods for managing Active Directory e-mail distribution groups and their memberships
  • ChangeContactsMembershipInDistributionGroup
  • ChangeUsersmembershipInDistributionGroup
  • CreateContact
  • CreateDistributionGroup
  • DeleteContact
  • DeleteDistributionGroup
  • GetJobStatus
  • ModifyContact
  • ModifyDistributionGroup
  • RenameDistributionGroup
Site Data (SiteData.asmx)
Methods that return metadata or list data from sites or lists
  • EnumerateFolder
  • GetAttachments
  • GetChanges
  • GetContent
  • GetList
  • GetListCollection
  • GetListItems
  • GetSite
  • GetSiteAndWeb
  • GetSiteUrl
  • GetURLSegments
  • GetWeb
Sites(Sites.asmx)
Methods for returning information about the collection or site template
  • ExportWeb
  • GetSiteTemplates
  • GetUpdatedFormDigest
  • ImportWeb
Search(spsearch.asmx)
Methods for searching via search services
  • Query
  • QueryEx
  • Registration
  • Status
Users & Groups(usergroup.asmx)
Methods for working with users role definitions and groups
  • AddGroup
  • AddGroupToRole
  • AddRole
  • AddRoleDef
  • AddUserCollectionToGroup
  • AddUserCollectionToRole
  • AddUserToGroup
  • AddUserToRole
  • GetAllUserCollectionFromWeb
  • GetGroupCollection
  • GetList
  • GetListAndView
  • GetListCollection
  • GetGroupCollectionFromRole
  • GetGroupCollectionFromSite
  • GetGroupCollectionFromUser
  • GetGroupCollectionFromWeb
  • GetGroupInfo
  • GetRoleCollection
  • GetRoleCollectionFromGroup
  • GetRoleCollectionFromUser
  • GetRoleCollectionFromWeb
  • GetRoleInfo
  • GetRolesAndPermissionsForCurrentUser
  • GetRolesAndPermissionsForSite
  • GetUserCollection
  • GetUserCollectionFromGroup
  • GetUserCollectionFromRole
  • GetUserCollectionFromSite
  • GetUserCollectionFromWeb
  • GetUserInfo
  • GetUserLoginFromEmail
  • RemoveGroup
  • RemoveGroupFromRole
  • RemoveRole
  • RemoveUserCollectionFromGroup
  • RemoveUserCollectionFromRole
  • RemoveUserCollectionFromSite
  • RemoveUserFromGroup
  • RemoveUserFromRole
  • RemoveUserFromSite
  • RemoveUserFromWeb
  • UpdateGroupInfo
  • UpdateRoleDefInfo
  • UpdateRoleInfo
  • UpdateUserInfo
Versions (Versions.asmx)
Methods for working with file versions
  • DeleteAllVersions
  • DeleteVersion
  • GetVersions
  • RestoreVersion
Views(Views.asmx)
Methods for working with list views
  • AddView
  • DeleteView
  • GetViewCollection
  • GetViewHtml
  • UpdateView
  • UpdateViewHtml
  • UpdateViewHtml2
Web Part Pages(WebPartPages.asmx)
Methods for working with Web Part Pages
  • AddWebPart
  • AddWebPartToZone
  • AssociateWorkflowMarkup
  • ConvertWebPartFormat
  • DeleteWebPart
  • ExecuteProxyUpdates
  • FetchLegalWorkflowActions
  • GetAssemblyMetaData
  • GetBindingResourceData
  • GetCustomControlList
  • GetDataFromDataSourceControl
  • GetFormCapabilityFromDataSourceControl
  • GetSafeAssemblyInfo
  • GetWebPart
  • GetWebPart2
  • GetWebPartCrossPageCompatibility
  • GetWebPartPage
  • GetWebPartPageConnectionInfo
  • GetWebPartPageDocument
  • GetWebPartProperties
  • GetWebPartProperties2
  • RemoveWorkflowAssociation
  • RenderWebPartForEdit
  • SaveWebPart
  • SaveWebPart2
  • ValidateWorkflowMarkupAndCreateSupportObjects
Webs(Webs.asmx)
Methods for working with sites and subsites
  • ·CreateContentType
  • ·CustomizeCss
  • ·DeleteContentType
  • ·GetActivatedFeatures
  • ·GetAllSubWebCollection
  • ·GetColumns
  • ·GetContentType
  • ·GetContentTypes
  • ·GetCustomizedPageStatus
  • ·GetListTemplates
  • ·GetWeb
  • ·GetWebCollection
  • ·RemoveContentTypeXmlDocument
  • ·RevertAllFileContentStreams
  • ·RevertCss
  • ·RevertFileContentStream
  • ·UpdateColumns
  • ·UpdateContentType
  • ·UpdateContentTypeXmlDocument
  • ·WebUrlFromPageUrl
MOSS Search (Search.asmx)
Methods for searching via MOSS (Microsoft Office SharePoint Server) Search services, which also includes a method to retrieve the managed search properties
  • GetSearchMetadata (Search managed properties)
  • Query
  • QueryEx
  • Registration
  • Status