Sunday, September 25, 2011

Disable automatic activation of SharePoint features in Visual Studio 2010.

When we write our custom solutions for SharePoint 2010, we must know that all our features will be activated automatically on every time we deploy the solution over the SharePoint site selected at project creation time.



This is the default configuration that we have inside SharePoint 2010 tools for Visual Studio 2010. When you are doing development of a custom event receiver that manage activation or deactivation events of a SharePoint feature. In this specific sample, we cannot debug our code.

To solve this problem, you can modify this configuration and select to don't activate your features every time you have to deploy your solution. To do this, simply you have to open the project properties page through the "Solution explorer" toolbox, select the "SharePoint" tab and choose the configuration named "No Activation".
 

As we can disable the automatic activation of our features, we also have the possibility to create custom configurations in which we can insert deploy and retract operations, app-pool recycles, features activation and command execution of pre/post deploy actions.

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters.


If you receive the following error in Visual Studio while packaging WSP:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters

then simply move all your projects from

C:\Users\YOUR_USERNAME\Documents\Visual Studio 2010\Projects\

to root drive

C:\Projects

Visual studio does not allow absolute path that exceeds 260 characters. so use short filenames when you create any WSP package and create your project on root directory to avoid long absolute paths.

Wednesday, September 21, 2011

Inbuilt method to Check if List Exist in SharePoint 2010.

In SharePoint 2007, one of the mostly required methods but not provided by Microsoft:
Checking if SharePoint List exists on Site or not?
If we directly use spWeb.Lists[“<ListName>”] and if list does not exist then it will throw an exception. To avoid such exceptions I have created following extension method:
public static bool IsListExists(this SPWeb spWeb, string listName)
{
    try
    {
        return spWeb.Lists.Cast<SPList>().Any(list => string.Compare(list.Title, listName, true) == 0);
    }
    catch (Exception ex)
    {
        ex.LogException("List does not exist", CommonConstants.EVENT_SOURCE, spWeb, spWeb.CurrentUser);
        return false;
    }
}
Now Microsoft is woke up, In SharePoint 2010 they have provided an inbuilt method method in the SPListCollection .Simply use this method instead of looping all the lists and check its existence.

SPList sampleList = spWeb.Lists.TryGetList("SampleList");
if (sampleList != null)
{
    // Code Block goes here
}

Hope this helps you...