Monthly Archives: February 2013

Build SharePoint List Event Receiver

I would like to show you to develop simple SharePoint List Event Receiver.
We could use same Project list and Project Report library that I’ve created from the previous post.

  1. Open Microsoft Visual Studio 2010 > File > New > Project > Empty SharePoint Project.
  2. Enter the Project Name, Location and Solution Name.
  3. Select Deploy as farm solution and click OK.
  4. Right click on the project and select Add > New Item.
  5. Select Event Receiver item and enter Event Receiver’s Name.
  6. In SharePoint Customization Wizard window:
    EventReceiver1
  7. My final solution will look like below.
    EventReceiver2
  8. Open EventReceiverProjectReport.cs and update the code to:
    using System;
    using Microsoft.SharePoint;
    
    namespace ProjectReportEventReceiver.EventReceiverProjectReport
    {
        ///
        /// List Item Events
        ///
        public class EventReceiverProjectReport : SPItemEventReceiver
        {
            ///
            /// An item was added.
            ///
            public override void ItemAdded(SPItemEventProperties properties)
            {
                base.ItemAdded(properties);
                if (properties.List != null && properties.List.Title.ToLower().Trim() == "project reports")
                {
                    SPListItem oItem = properties.ListItem;
                    oItem["ReportComment"] = String.Format("Created by Event Receiver on {0}", DateTime.Now.ToString("dd/MM/yyyy"));
                    oItem.Update();
                }
            }
    
            ///
            /// An item was updated.
            ///
            public override void ItemUpdated(SPItemEventProperties properties)
            {
                base.ItemUpdated(properties);
                if (properties.List != null && properties.List.Title.ToLower().Trim() == "project reports")
                {
                    SPListItem oItem = properties.ListItem;
                    oItem["ReportComment"] = String.Format("Updated by Event Receiver on {0}", DateTime.Now.ToString("dd/MM/yyyy"));
                    oItem.Update();
                }
            }
        }
    }
    
  9. Build and Deploy the project.

Now its time to test it.

  1. Upload document to Project Reports library.
    TestResult1
  2. ReportComment column will be set by event receiver automatically.
    EventReceiver3
Advertisements

Utilize Lookup column in Calculated column SharePoint list / libraries

Have you every realize that you could NOT use Lookup column in your Calculated column formula. Below is few snapshots to show the limitation.

Project list

ProjectList

Project Reports library

ProjectReportSetting1

ProjectReportSetting2

I would like to have ReportComment = [Project] & ‘ ‘ & [Created by] & ‘ ‘ & [Last Modified Date]

But I could no do it since there is no Project Lookup column from the available list of columns.

Solution

In this article, I will show you the trick to utilize your Lookup column in Calculated column formula using SharePoint Designer workflow.

  1. Go to Project Report Library Settings and Delete existing ReportComment column.
  2. In Project Report Library Settings, Add new column ReportComment column as Single Line of text.
  3. Open Microsoft SharePoint Designer.
  4. File > Open Site > enter your site URL.
  5. From Ribbon > List Workflow > Project Reports.
    SPD1
  6. In Create List Workflow window, enter Name and Description.
    SPD2
  7. Create workflow to look like below.
    SPD3
  8. Do not forget to set the Start Options of the workflow.
    SPD4
  9. Save and Publish the workflow.

Now its time to test it.

  1. Upload document to Project Report library.
    TestResult1
  2. Workflow will set the ReportComment column.
    TestResult2

 

Hopefully it might save your time and Thank you ..

Debug your SharePoint site

I know this is nothing new and most of us knew it already, but I might just post in my blog for my own references. When you open SharePoint page, sometimes you get annoying error “Unexpected error occurred” and there is no further explanation to it.

By enable debugging in your site web.config file, you could see the trace log and will be more helpful when you googling.

Steps to modify your web.config file:

  • Go to your web.config file normally located at C:\inetpub\wwwroot\wss\VirtualDirectories\<port number>
  • Backup your current web.config file
  • Open web.config file with notepad
  • Update attributes like below:
<configuration>
  <SharePoint>
    <SafeMode CallStack="true" />
  </SharePoint>
  <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
  </system.web>
</configuration>

Disable loop back check

I know this article about Disable loop back check is very common and you could find easily in Google  That is why I thought its very useful to add to my blog for my reference as well.

There are two methods to do this:

Method 1: Specify host names (Preferred method if NTLM authentication is desired)

To specify the host names that are mapped to the loopback address and can connect to Web sites on your computer, follow these steps:

  1. Set the
    DisableStrictNameChecking

    registry entry to 1. For more information about how to do this, click the following article number to view the article in the Microsoft Knowledge Base:

    281308 Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name
  2. Click Start, click Run, type regedit, and then click OK.
  3. In Registry Editor, locate and then click the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  4. Right-click MSV1_0, point to New, and then click Multi-String Value.
  5. Type BackConnectionHostNames, and then press ENTER.
  6. Right-click BackConnectionHostNames, and then click Modify.
  7. In the Value data box, type the host name or the host names for the sites that are on the local computer, and then clickOK.
  8. Quit Registry Editor, and then restart the IISAdmin service.

Method 2: Disable the loopback check (less-recommended method)

The second method is to disable the loopback check by setting the DisableLoopbackCheck registry key.

To set the DisableLoopbackCheck registry key, follow these steps:

  1. Set the
    DisableStrictNameChecking

    registry entry to 1. For more information about how to do this, click the following article number to view the article in the Microsoft Knowledge Base:

    281308 Connecting to SMB share on a Windows 2000-based computer or a Windows Server 2003-based computer may not work with an alias name
  2. Click Start, click Run, type regedit, and then click OK.
  3. In Registry Editor, locate and then click the following registry key:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
  4. Right-click Lsa, point to New, and then click DWORD Value.
  5. Type DisableLoopbackCheck, and then press ENTER.
  6. Right-click DisableLoopbackCheck, and then click Modify.
  7. In the Value data box, type 1, and then click OK.
  8. Quit Registry Editor, and then restart your computer.
%d bloggers like this: