Connecting web parts programmatically

We need SPLimitedWebPartManager to connect the Web parts with ASP.NET style interfaces. The steps for this are:

  1. Get the SPLimitedWebPartManager instance on the page;
  2. Get the provider and consumer Web parts need to be connected;
  3. Get the connection points for the provider and consumer Web parts;
  4. Connect them using SPConnectWebParts method. If necessary, certain transforming needs to be in place for compatible interfaces
SPWeb web = (SPWeb)properties.Feature.Parent;      
SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared);      
System.Web.UI.WebControls.WebParts.WebPart provider= mgr.WebParts["Provider"];   
System.Web.UI.WebControls.WebParts.WebPart consumer= mgr.WebParts["Consumer"];  
ConsumerConnectionPoint addConsumerConnPoint = mgr.GetConsumerConnectionPoints(consumer)["AddressConsumer_ot"];   
ProviderConnectionPoint addProviderConnPoint = mgr.GetProviderConnectionPoints(provider)["AddressProvider_ot"];      
mgr.SPConnectWebParts(provider, addProviderConnPoint, consumer, addConsumerConnPoint);

Hide the content type field in SharePoint

  1. Open SharePoint Designer and navigate to the site that contains the list or document library you wish to customize.
  2. Expand the folder named “Forms” under the desired list or document library.  You should see about seven .aspx pages (AllItems.aspx, EditForm.aspx, NewForm.aspx, etc)
  3. Open the Form.aspx page and switch to the “code” view to edit the HTML of the page.
  4. Paste the JavaScript code immediately below the the following HTML tag
  6. This will add the JavaScript to the HTML inside the content placeholder tag.  Note: be sure to include the entire script below, including the script tags.
  7. Modify the “hidefields()” section of the JavaScript code to refer to each SharePoint list field name to hide.  For example, the code sample below will hide the SharePoint fields named Title, Document Link, and PublishDate    Notice that you do not need to worry about internal field names or field types like other JavaScript techniques, you simply need to know the name of the field.
  8. Save the changes.  Select “Yes” when prompted to “…customize the page from the site definition…”
  9. Test the form
  10. Javascript Code

    function findacontrol(FieldName) {  
       var arr = document.getElementsByTagName("!");  
       // get all comments  
       for (var i=0;i < arr.length; i++ )  
          // now match the field name  
          if (arr[i].innerHTML.indexOf(FieldName) > 0)  
          {         return arr[i];      }  
    function hideFields() {  
       var control = findacontrol("Title");"none";  
       control = findacontrol("Content Type");"none";  

Delete multiple users programmatically in SharePoint

                        SPWeb web = new SPSite(siteUrl).OpenWeb();  
                        for (int i = web.SiteUsers.Count - 1; i >= 0; i--)  
                            SPUser siteuser = web.SiteUsers[i];  
                                if (siteuser.IsSiteAdmin == false)  
                                    catch(SPException ex)