Enabling ECB menu on a custom column in SharePoint 2013

Most of you would be aware of the fact that in SharePoint 2010 we could move the ECB menu on any custom column or for that matter a different columns than what was when the List/Library got created. There is a blog for the same (as below). http://blogs.msdn.com/b/chunliu/archive/2010/09/27/enabling-ecb-menu-on-a-custom-column-in-sharepoint-2010-part-1.aspx http://blogs.msdn.com/b/chunliu/archive/2010/09/29/enabling-ecb-menu-on-a-custom-column-in-sharepoint-2010-part-2.aspx As part of this blog we are going to see how to achieve the same in SharePoint 2013. The basic concept in SharePoint 2013 still remains the same as SharePoint 2010. However, Since the Design View has been removed from the SharePoint Designer 2013 hence I wanted to put across the modified steps to be performed in the absence of the Design View. Steps: As we all know by default the ECB menu is present on the Name column in case of a SharePoint Document Library and on the Title column in case of a SharePoint list. Here we are gong to take the example of a SharePoint Document Library. Note: The steps remain the same for a SharePoint List as well

  1. Navigate to the Document Library/List where you want to move the ECB menu to a different column. Ensure that the column on which you want to move the ECB menu is present in the view. In our example the column/field is Title

image

2.   Navigate to the Library Tab in the ribbon of the document library and select the Modify view in SharePoint Designer (Advanced) option image 3.   This will open the view in SharePoint Designer (Use SharePoint Designer 2013) image 4.   In the Editor locate the <View> element  as shown below image 5.   Under <View> locate  <ViewFields> and then the <FieldRef Name=”Title”> or the field where you want to enable the ECB menu and then add the attribute ListItemMenu=”TRUE” image 6.   Save the changes and visit your document library to verify that ECB has been enabled on the Title field. image

Hiding SharePoint Lists

Sometimes we do feel a need to hide SharePoint Lists. Following are few ways which could some in handy while trying to achieve this objective.
Using SharePoint Designer:

  1. Start SharePoint Designer and open your site.
  2. Click on the “Lists and Libraries” in the Navigation pane
  3. Select the list/library which you need to hide
  4. On the details page check the “Hide from browser” checkbox and save
  5. To unhide the list un-check the checkbox and save 
sharepoint designer
SharePoint Designer

Using Code:
The other way is to obviously do this through code. SPList has a property as Hidden which can be set to true or false

using (SPSite site = new SPSite("http://YourSiteUrl"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["Announcements"];
                        //Set this property to true or false accordingly
                        list.Hidden = false;
                        list.Update();
                    }
                }

Mask SharePoint User Details inside a SharePoint list/library

Working for a recent client there was a need to “mask” user information from a Sharepoint list. The list was intended to store user grievances and complaints and the client did not want to store the information of the user entering the information. It was required to keep the information completely anonymous.
So, I found that the following property of a SPList could be the right thing to do in this case
SPList.ShowUser
The default behaviour of SharePoint is to store the user information like shown below

List Without Mask
Without Mask

So, now run the following PowerShell command and see the difference

$web=Get-SPWeb "http://sharepointurl"
$list=$web.Lists["Employee Grievances"]
$list.ShowUser=$false
$list.Update() 
List With Mask
With Mask

So, there you go. Happy SharePoint”ing”

Associate Event Handlers in SharePoint to specific list

In Windows SharePoint Services 3.0, there are three fundamental ways to register an event handler:

  • Through the object model, as the SPWeb and SPList classes now each provide an EventReceivers property through which to access the collection of event receiver definitions for the Web site or list. You can add new event receivers by calling the Add method.
  • Declaratively by list type, for example, to register an event handler for all announcements lists. In a Feature.xml file, you can register an event handler by list template ID. When the containing feature is activated per SPWeb object, you can register the event handler for any list of the specified type.
  • Declaratively by content type, for example, to register an event handler for all documents of a specific type. Within the XML for a content type definition, you can register event receivers.

So if you need to make your list event handler specific to list then,

  1. Create a custom list type using a list definition and then attach the event handler to it
  2. Create a custom content type for your list and attach the event handler to the content type, this will make the event handler specific to list
  3. Register the event handler using object model to the list you desire. You can us e this free tool which facilitates this (http://www.u2u.info/SharePoint/U2U%20Community%20Tools/EventHandlerExplorer.zip)
  4. Check for the list in the event handler code before executing the code.

Read email address of a SharePoint list/library programmatically

You can try SPList.EmailAlias property of a SPList object. It will return the email adress of the list as string

SPSite site = new SPSite("http://yoursite");
SPWeb web = site.OpenWeb();
SPList list = web.Lists[listGuid];
string emailAddress = list.EmailAlias;