Archive

Archive for the ‘MOSS 2007’ Category

SharePoint – Timer Job Executing Multiple Times

March 13, 2014 1 comment

Custom timer jobs are created by inheriting SPJobDefinition class. This class is available under Microsoft.SharePoint.Administration namespace.

Recently I was working on a timer job which was scheduled to run every 5 minutes. After deployment I found the job is invoked multiple times during each 5 minute cycle. In my case this was executing 10 times. This happened because I have 10 content database. To avoid this we should make use of the SPJobLockType enumeration.

public MyCustomTimerJob(string jobName, SPWebApplication webapp) : 
base(jobName, webapp, null, SPJobLockType.Job) {
	this.Title = "My Custom Timer Job";
}

Hope this helps!

Advertisements

OleDBConnection – Unspecified error

August 5, 2013 1 comment

On top of SharePoint 2010, I was trying to create an excel parser where I hit with this strange “Unspecified error”. The exception is getting generated from “OleDBConnection.Open” method

There was no inner exceptions or stack traces, which made it difficult to find the root cause. After trying out different steps like uninstalling office, restarting iis etc. eventually I resolved it by the below 3 steps

  1. Download latest Access Databas Engine http://www.microsoft.com/en-in/download/details.aspx?id=13255. Ensure to select the correct platform 32 vs 64
  2. Connection string = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=fileLocation;Extended Properties=”Excel 12.0 Xml;HDR=Yes;IMEX=1”
  3. In the web configuration file turn off Impersonation <identity impersonate=”false” />

In the connection string I am using HDR=Yes, this mean the first row in the excel file is a header row. IMEX=1 will force the excel cells to be treated as Text rather than the Excel General type which converts the data (The feature I hate most)

SharePoint Survey List – EventReceiver

SharePoint Survey list behaves differently compared to others. A survey can have many questions, that can be on different pages. There must be scenarios where we need to do calculations once a Survey response is completed. For doing this the best option is event receiver customization. In this case we need to handle both ItemAdded and ItemUpdated events.

When a user respond’s to a survey the value in field Completed will be 255. Once the user clicks on the finish button the value changes to 1. Hence in the receiver we need to take action only once the value equals 1.

Below is a template you can use

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace Survey
{    
    /// <summary>
    /// List Item Events
    /// </summary>
    public class SurveyListReceiver : SPItemEventReceiver
    {
       /// <summary>
       /// An item was added.
       /// </summary>
       public override void ItemAdded(SPItemEventProperties properties)
       {
           try
           {
               if (properties.ListItem["Completed"] != null && properties.ListItem["Completed"].ToString() == "1")
               {
                   //Survey is complete. Do The Action
               }
           }
           catch
           {
           }
           base.ItemAdded(properties);
       }

       /// <summary>
       /// An item was updated.
       /// </summary>
       public override void ItemUpdated(SPItemEventProperties properties)
       {
           try
           {
               if (properties.ListItem["Completed"] != null && properties.ListItem["Completed"].ToString() == "1")
               {
                   //Survey is complete. Do The Action
               }
           }
           catch
           {
           }
           base.ItemUpdated(properties);
       }
    }
}

WSS 3.0 Site Actions Menu Item

Using a feature to add new menu item in Site Actions.

Create a WSP project & add a feature to the solution. Edit feature file as below

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="B1FB6ECC-0039-4E08-A4B4-80B5B3C8DCE3"
   Title="Sample Feature"
   Description="New menu item on Site Actions"
   Version="1.0.0.0"
   Scope="Site"
   xmlns="http://schemas.micræsoft.com/sharepoint/">
      <ElementManifests>
         <ElementManifest Location="SampleFile.xml" />
      </ElementManifests>
</Feature>

Create an Xml file, called “SampleFile.xml” on the feature folder
Edit the file and add the following content

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.micræsoft.com/sharepoint/">
   <CustomAction
       GroupId = "SiteActions"
       Location="Microsoft.SharePoint.StandardMenu"
       Sequence="1000"
       Title="Your Title">
       <UrlAction Url="/_layouts/YourPage.aspx"/>
   </CustomAction>
</Elements>

Add & Deploy WSP

stsadm –o addsolution –filename SampleSolution.wsp
stsadm -o deploysolution -name SampelSolution 
   -url http://siteurl

Activate the new feature by running the following command

stsadm –o activatefeature -filename SampleFeature \feature.xml -url http://siteurl
Categories: MOSS 2007, SharePoint, WSS 3.0