Showing posts with label Check if SharePoint Sandbox solution exits in Sitecollection Gallery. Show all posts
Showing posts with label Check if SharePoint Sandbox solution exits in Sitecollection Gallery. Show all posts

Sunday, November 24, 2013

• CheckSolutionExits- “checks if the sandbox solution already exists in the sitecollection solution gallery” (Signature : sitecollection url(string),wspname(string))

CheckSolutionExits:-


    public static bool CheckSolutionExits(string sitecollection, string wspname)
        {
            #region Solution exits
            bool Found = false;
            try
            {

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(sitecollection))
                    {

                        SPList solGallery = site.GetCatalog(SPListTemplateType.SolutionCatalog);
                        foreach (SPListItem item in solGallery.Items)
                        {
                            if (item.File.Name.Equals(wspname))
                            {
                                Found = true;
                                break;

                            }
                        }

                     

                    }

                });

            }

            catch (Exception ex)
            {
               throw ex;
            }

            #endregion
            return Found;
        }