Tuesday, May 18, 2010

Add a WebPart into the Rich Content of a wiki page in SP2010

After a long struggle looking in the SP API for how to insert a WebPart in the "rich content" of a wiki page, i found the answer. Thanks to Stefan Stanev for posting the answer to my question.

I have modified the code a bit to suite my needs

SPSite osite = properties.Feature.Parent as SPSite; 
   using (SPWeb oWeb = osite.OpenWeb(osite.RootWeb.ID)) 
  {
    //SPLimitedWebPartManager webpartsManager =  oWeb.GetLimitedWebPartManager(oWeb.RootFolder.WelcomePage, PersonalizationScope.Shared);

   SPFile file = oWeb.GetFile(oWeb.RootFolder.WelcomePage);
   Guid cwpID = AddWebPartToRichContent(file);
   Guid xlvID = AddListWebPartToRichContent(file, "Announcements");

  }

private Guid AddWebPartToRichContent(SPFile file)
{
// NOTE: we assume that the SPFile was checked out
// get the limited wp manager for that SPFile
SPLimitedWebPartManager mngr = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

// create a sample content editor wp
ContentEditorWebPart cwp = new ContentEditorWebPart();
cwp.Title = "My editor";

// add the web part to the special wpz zone
mngr.AddWebPart(cwp, "wpz", 0);

// store the web part's internal ID
Guid cwpID = mngr.GetStorageKey(cwp);

// get the list item for that SPFile
SPListItem item = file.Item;

// update the PublishingPageContent field value
item["WikiField"] += this.GetEmbeddedWPString(cwpID);

// update the item
item.SystemUpdate(false);

// the SPFile instance can be checked in, published, approved afterwards

return cwpID;

}

private Guid AddListWebPartToRichContent(SPFile file, string listTitle)
{
// NOTE: we assume that the SPFile was checked out
// get the limited wp manager for that SPFile
SPLimitedWebPartManager mngr = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

// create a sample XLV
XsltListViewWebPart xlv = new XsltListViewWebPart();

// get a target list
SPList list = file.ParentFolder.ParentWeb.Lists[listTitle];

// set the ListName property with the capitalized list ID w/o the curly braces
xlv.ListName = list.ID.ToString("B").ToUpper();

// use the schema of the default view
xlv.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();

// add the web part to the special wpz zone
mngr.AddWebPart(xlv, "wpz", 0);

// store the web part's internal ID
Guid xlvID = mngr.GetStorageKey(xlv);

// get the list item for that SPFile
SPListItem item = file.Item;

// update the PublishingPageContent field value
item["WikiField"] += this.GetEmbeddedWPString(xlvID);

// update the item
item.SystemUpdate(false);

// the SPFile instance can be checked in, published, approved afterwards

return xlvID;

}

private string GetEmbeddedWPString(Guid wpID)
{
const string form = @"
                                    

                                    

                                    

                                    
                                   
";

// set the web part's ID as part of the ID-s of tho div elements
return string.Format(form, wpID);

}


I hope this would help someone out there.

Update: Found another helpful post
http://www.habaneros.com/mobile/blog/10-03-30/Programmatically_Change_Content_on_a_Wiki_Page_in_SharePoint_2010.aspx

Monday, April 19, 2010

Twitter webpart for SharePoint 2010

I've been working on a couple of social solutions for SharePoint 2010. One of the solutions was a Twitter webpart that will search for tweets based on a keyword, or a user.
The following properties can be customized:

  • Display poster profile image
  • Tweets limit
  • Search by a user and/or words
  • Refresh intervals (60 sec default)

The webpart will refresh on a set interval to load more tweets automatically.
It is also possible to tag the tweets with keywords from SharePoint taxonomy.

Saturday, April 17, 2010

SharePoint 2010 reaches RTM!

Today SharePoint 2010 RTM was released. This is an exciting milestone for Microsoft. Volume License customers will be able to download SharePoint on the 27th of April if they have an active SA. Customers who do not have the SA will be able to download it on 1st of May.

For more information, check the Microsoft SharePoint Team Blog

Friday, April 9, 2010

Activity Feed being empty with Claims Enabled Web Applications

I was having trouble aggregating my colleagues' activities into my news feed page. After searching for a solution on the internet, found out that i needed to do two things


  • Add colleagues 
  • Enable the "User - Activity Feed Job" because it was disabled for some reason.

Then when i went to the "My newsfeed" page, i found no feeds still. I didn't get the feeds in my "recent activities" either. After some investigations i found out that the "All Authenticated" users for the Claims provider that the Web Application is using must be added to have read permissions on the social data. You can do this by going to the User Profile Management page and then going to the "Manage User Permissions" page.

After doing this, and then re-running the job. The feeds appeared :)

Thursday, January 28, 2010

New SharePoint and Office 2010 Image availabe

Overview
This download contains a two Virtual Machine set for evaluating and demonstrating Office 2010 and SharePoint 2010. 
Virtual machine “a” contains the following pre-configured software: 
1. Windows Server 2008 SP2 Standard Edition x64, running as an Active Directory Domain Controller for the “CONTOSO.COM” domain with DNS and WINS 
2. Microsoft SQL Server 2008 SP2 Enterprise Edition with Analysis, Notification, and Reporting Services 
3. Microsoft Office Communication Server 2007 R2 
4. Visual Studio 2010 Beta 2 Ultimate Edition 
5. Microsoft SharePoint Server 2010 Enterprise Edition Beta 2 
6. Microsoft Office Web Applications Beta 2 
7. FAST Search for SharePoint 2010 Beta 2 
8. Microsoft Project Server 2010 Beta 2 
9. Microsoft Office 2010 Beta 2 
10. Microsoft Office Communicator 2007 R2 


Virtual machine “b” contains the following pre-configured software: 
1. Windows Server 2008 R2 Standard Evaluation Edition x64, joined to the “CONTOSO.COM” domain 2. Microsoft Exchange Server 2010 Active directory has been preconfigured over 200 “demo” users with metadata in an organizational structure. All of these user profiles have been imported and indexed for search within SharePoint Server 2010, with “contoso\administrator” granted administrator permissions. 
SharePoint Server 2010 has been configured in a “Complete” farm using Kerberos authentication and the default SQL Server 2008 instance for data, and has a site collection created using the Team Site template at http://intranet.contoso.com/ and a FAST Search Center at http://intranet.contoso.com/search/


Performance Considerations 
1. If possible, unpack and run the VM image on a separate, fast hard drive (7200 RPM or better) from the operating system of the host machine. If this is being done on a laptop, a second internal drive or external eSATA drive works best, though USB 2.0 (make sure it's 2.0, 1.1 is too slow) or Firewire is acceptable. For absolute best performance use a second internal SSD drive.

To download it, follow the below link

User profile import will not work when Office WebApps are installed on the server

From working with the Profile Import Service Application, and testing out what SharePoint 2010 can do, we have found out that if you have Office Web Apps installed on your server, the Profile Import will not work.

This is a known bug and will be fixed in a future release.