1

I set up several webparts through different sites in sp 2013 - however, most webparts have the number [2] next to it, i.e. Documents [2].

I've looked all over to make sure there is no another webpart on the same page, nor anywhere else, and nothing. Tried changing the name and can't delete the number [2].

3 Answers 3

3

Try appending ?contents=1 to the url. This will take you to the web parts maintenance page. CHeck to see if there are any closed web parts on the page. If so, remove them and you should see the [2] go away.

4
  • please pardon my ignorance but... what do you mean by appending ?contents=1 to the URL?
    – carlos
    May 27, 2015 at 14:49
  • in the address bar in your browser, add that to the end of the url, if there is a question mark already, replace it with an ampersand. May 27, 2015 at 14:53
  • worked!! i am able to all the webparts, had to to match their ID to the actual webpart but worked well.. THank you
    – carlos
    May 27, 2015 at 15:30
  • Great! If this answered your question, be sure to mark it as answered by ticking the check box. May 27, 2015 at 16:02
1

Can you try searching for the hidden webparts if there are any and try to delete them and add the webaprt again.


Today for something regarding one of the new features of SharePoint 13. There is the new attribute “ReplaceContent=TRUE” for the element in .

Until SharePoint 2010, whenever we reactivate the PageLayout feature (the feature that provisions the page layouts in a master page gallery), web parts that have been added to the page layout are duplicated on the new page and we do not have a very standard solution to resolve this problem except for writing a feature receiver and removing the duplicated web parts.

In SharePoint 2013 is the new attribute “ReplaceContent=TRUE” of the element and if we use this when provisioning the page layout it overrides the existing web parts on the page layouts. So whenever we create a new page from the given page layouts, web parts are not duplicated.

Example

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Module Name="MyPageLayouts" Url="_catalogs/masterpage" RootWebOnly="TRUE">  
    <File Path="MyPageLayouts\MyPageLayout.aspx" Url="MyPageLayouts.Intranet/MyPageLayout.aspx" Type="GhostableInLibrary" ReplaceContent="TRUE">  

<!—- All our web parts goes here -->  

    </File>  

  </Module>  

Have a look at the preceding example, I have set the ReplaceContent=”TRUE”. Because of this whenever I change, add or delete a web part in this elements.xml file and I need to reactivate the feature, the web parts on the page layouts are not duplicated but they do get overridden.

Other Usage example

I'll like to share one more scenario related to this, I have a sandbox solution that I am deploying on Office 365. I was uploading my package file (.wsp) to the Solution Gallery and activating it. In my package I have one feature that is deploying my CSS file in the master page gallery since I do not have file system access. I had a change in CSS file, I did the change, packaged the solution, deactivated the solution first, uploaded it to the solution gallery and activated it. But my CSS changes are not reflected. Then I remembered the “ReplaceContent” attribute and I used it in the module element while provisioning the CSS file and wonder happened? It worked like a charm.

1
  • tried searching and nothing...
    – carlos
    May 27, 2015 at 14:47
1

Removing all duplicated Web Part instances: The first approach you might consider is iterating through the WebParts collection of the particular Page Layout, comparing the XML of each one of them and removing any duplicate found. You could do this for example like that:

using (SPSite site = new SPSite("http://sharepoint"))
{
  SPList list = site.GetCatalog(SPListTemplateType.MasterPageCatalog);
  SPListItemCollection items = list.Items;
  List<string> webParts = new List<string>();

  // find the right Page Layout
  foreach (SPListItem item in items)
  {
    if (item.Name.Equals("CustomPageLayout.aspx",
      StringComparison.CurrentCultureIgnoreCase))
    {
      SPFile file = item.File;
      // get the Web Part Manager for the Page Layout
      SPLimitedWebPartManager wpm =
        file.GetLimitedWebPartManager(PersonalizationScope.Shared);
      // iterate through all Web Parts and remove duplicates
      while (wpm.WebParts.Count > 0)
      {
        StringBuilder sb = new StringBuilder();
        XmlWriterSettings xws = new XmlWriterSettings();
        xws.OmitXmlDeclaration = true;
        XmlWriter xw = XmlWriter.Create(sb, xws);
        System.Web.UI.WebControls.WebParts.WebPart wp =
          wpm.WebParts[0];
        wpm.ExportWebPart(wp, xw);
        xw.Flush();
        string md5Hash = getMd5Hash(sb.ToString());
        if (webParts.Contains(md5Hash))
          wpm.DeleteWebPart(wp);
        else
          webParts.Add(md5Hash);
      }
    }
  }
}

The first step is to get the reference to the Page Layout. Then you will obtain a reference to the SPLimitedWebPartManager of the given Page Layout which contains information about all Web Parts attached to that Page Layout. Last but not least you will iterate through the WebPart collection and remove any duplicate Web Parts found. To do the comparison I have used an MD5 hash which I store in a list. I compute the hash using the method presented on the MSDN site. In my opinion the above method will work in almost every case because you are not likely going to display two exactly the same Web Parts on one page. It's biggest limitation is the lack of distinction between Web Parts provisioned by different Features. However, if your main goal is removing the duplicate Web Parts, it might be just something for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.