Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have been trying to do this for a while now its a huge pain as I can't seem to find any good guides to show all steps for adding a web part to a page using a feature staple.

I have the feature staple ready and its working (tried it out with CSS) but I have no clue where to add code to get the webpart so it appears on every MySite when it is created.

I followed this guide http://www.greggalipeau.com/2011/07/12/sharepoint-provision-default-webparts-for-mysites/comment-page-1/#comment-1616 but in the code thats provided I don't know what to replace 'Treasury_MySites' with and what libraries to import for that PrivacyStatement. Someone please help! Should I do it like this guide says or is there a better way?

Thank you!

share|improve this question

2 Answers 2

Treasury_MySites.PrivacyStatement.PrivacyStatement is the WebPart Greg is adding to the default.aspx of the MySites. You should replace that with the WebPart you want to add and then set all the properties to the wanted values.

share|improve this answer
    
So then does my web part need to be in this feature? I want to add a web part that is already on the SharePoint Web Part Gallery. Basically its a web part that I created and uploaded to SharePoint myself. How would I use it? Thanks again! –  Tudor Jul 13 '12 at 21:29
    
No the web part doesn't need to be in the same feature, but the code needs to be able to create an instance of it. The easist is if it at least has a reference to the dll with the web part, but otherwise it can be done through reflection. –  Per Jakobsen Jul 13 '12 at 21:33
    
Thanks! So where would be the best place to store the DLL? Right now I've linked to it in the web part project folder but there is a better location? Also since I've linked to it in the project folder I can now edit the code from Greg and it seems to be working but I have an error with the last line: "The best overloaded method match for 'Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager.AddWebPart(System.Web‌​.UI.WebControls.WebParts.WebPart, string, int)' has some invalid arguments" Any idea why this is? Is it because my web part isnt part of the WebParts.WebPart library? –  Tudor Jul 13 '12 at 21:42
    
Sounds strange. The only requirement is that your webpart inherits from System.Web.UI.WebControls.WebParts.WebPart (or from the SharePoint one which then inherits from the WebControl one) –  Per Jakobsen Jul 14 '12 at 14:22
    
hmm, any other ideas how to get around this? My web part is a CoreResultsWebPart that I've cutomized and it uses these libraries so I'm not sure why the problem comes up: using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint.WebControls; using Microsoft.Office.Server.Search.Query; using Microsoft.Office.Server.Search.WebControls; I have no idea how to go forward with this so I can deploy the webpart on all My Sites. –  Tudor Jul 16 '12 at 16:27

If you log in as the farm administrator account (not the farm account) and edit the page layout of your MySite, it will apply that change across the board to everyone's MySites.

Would that do the trick? No stapling required.

share|improve this answer
    
I'm not sure, I need this web part to show up on each My Site, even new ones after they are created. From my readings the best way to go is with feature stapling however that seems to be causing quite a few problems for me (see above comments). Thanks! –  Tudor Jul 16 '12 at 17:15
    
Yep, this is also an acceptable method to achieve that. FYI. –  RJ Cuthbertson Jul 18 '12 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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