Pages

Search This Blog

Monday, April 18, 2011

Programmatically check a WSP is deployed on a Web Application or not

Sometimes we have a scenario like we have to check that whether a particular wsp (Solution Package) is deployed on a Web application or not.
Suppose we have a feature and on the feature activation we need to add a webpart on some page of a site but that webpart is not packaged in the Feature Deployment Solution Package rather it’s a part of some other wsp package.
So during the activation process we have to know whether the webpart which we are going to add through feature is deployed on the webapplication or not.
Below is the code snippet with the help of which we can check that whether a particular wsp package is deployed on a webapplication or not.
private static bool CheckWSPDeployedStatus(SPSite objSite)
        {
            System.Collections.ObjectModel.Collection<SPWebApplication> objWebApplications = objSite.WebApplication.Farm.Solutions["Sample.wsp"].DeployedWebApplications;
            if (objWebApplications != null && objWebApplications.Count > 0)
            {
                if (objWebApplications.Contains(objSite.WebApplication))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

No comments:

Post a Comment