"The day you stop learning SharePoint is the day you stop using it."

Return the Current Site in an Event Receiver; the site in which event occurred.

In an ItemUpdated Event Receiver we were accessing two custom lists for reading values and for that we required to return the current site in which the event occured.
Simply writing SPSite mySite = new SPSite("http://yoursitename"); does not make sense. Because you might don’t know where you need to deploy the Event Receiver, hence hard-coding the Site URL is a bad practice. The below code shows how to return current site URL.

namespace ItemUpdateFeatureReceiver
{
 public class Class1 : SPItemEventReceiver
 {
  private SPWeb _web;

  public SPWeb myWeb
  {
    get
    {
      return _web;
    }
    set
    {
      _web = value;
    }
  }

//Property that returns a custom list named “Document Type”
public SPList CustomList1
{
  get
  {
    SPList myList = myWeb.Lists["Document Type"];
    return myList;
  }
}

//Property that returns a custom list named “Document Sub-Type”
public SPList CustomList2
{
  get
  {
    SPList myList = myWeb.Lists["Document Sub-Type"];
    return myList;
  }
}


public override void ItemUpdated(SPItemEventProperties properties)
{
  //Returns the current site in which event occured
 
  myWeb = properties.OpenWeb();
  
  //your code
}
Share:

When working with Document Panel Properties in Microsoft Word, better check out the “Look Up” field

If you have restored a site/site collection to new site/site collection and you are working with Quick Parts in Microsoft then beware of the Look Up fields. Look Up fields will not display values in your new restored site unless you delete it and create it once again. This is because the look up field internally stores the GUID of the list to which it looks up for values and when the site is restored to a new site/site collection and you look for values in document panel properties in MS Word, you find it blank.

Solution: You need to simply create new look up field(s) with the same name as previous ones and yeah you are done. !! Keep the name of the new Look Up fields same you may have referred your custom SharePoint Designer Workflow, code behind or somewhere else.

Share:

SharePoint-StackExchange Moderator

Author's Profile

My photo
India
A SharePoint Enthusiast working as a Lead Solution Architect for an IT Software & Consulting Company in Mumbai. I believe in giving back to the community through which I also learn and develop and eventually grow as an individual and professional. This blog is a small contribution to the community where I live in and may help someone who is seeking knowledge like me.

Popular Posts

Powered by Blogger.

Contact Form

Name

Email *

Message *

Total Pageviews