Friday, February 18, 2011

If you ever wondered how you can do this “without code” J you can do it by placing two WebParts on a SP page; an InfoPath Form WebPart and a Query String Filter WebPart. You then make a connection between the two passing the value from the Query String Filter to the InfoPath form WebPart.
Note the following:
  • This will not work for “lookup” fields if you use the default SP list InfoPath form (That’s Why I thought you can’t do it originally for lookups). However, you can expose the “lookup” dropdown field if you create a new InfoPath form using the method below.
  • Make sure you add the “field” in your InfoPath to the list of allowable fields to be used in connections.



References:

And here is how you can do it with Code behind.

Friday, January 21, 2011

Retrieve Activities from the SharePoint 2010 Activity Feeds

I've recently worked on a webpart that will let you retrieve activities for the logged in user and display them using the default template of the activity.

The webpart gets an instance of the ActivityManager object and the UserProfile object of the logged in user. After you get the reference, you can then retrieve the activity events using the ActivityManager.GetActivitiesByUser() method. Then you retrieve the resource (.resx) file corresponding to that particular ActivityEvent replacing the values with the ActivityEvent values as shown the code below


            string userName = Environment.UserDomainName + "//" + Environment.UserName;
            SPServiceContext currentContext = SPServiceContext.GetContext(SPContext.Current.Site);

            //Get the UserProfileManager from SPServiceContext.
            UserProfileManager userProfMan = new UserProfileManager(currentContext);

            //Get the current user.
            UserProfile currentUser = userProfMan.GetUserProfile(userName);

            //Get the ActivityManager from the user and context.
            ActivityManager activityMan = new ActivityManager(currentUser, currentContext);

            ActivityEventsCollection eventsCollection = activityMan.GetActivitiesForMe(10);

            foreach (ActivityEvent activity in eventsCollection)
            {
                ActivityType activityType = activityMan.ActivityTypes[activity.ActivityTypeId];
                ActivityTemplate activityTemplate = activityType.ActivityTemplates[bool.FalseString];
                string templateStr = SPUtility.GetLocalizedString(activityTemplate.TitleFormatLocStringResourceFile, "$Resource:" + activityTemplate.TitleFormatLocStringName, (uint)CultureInfo.CurrentUICulture.LCID);
              
                //The line below returns null for the "Publisher".
                //HOWEVER, If i step through the code in debug mode, the values get populated eventually
                templateStr = templateStr.Replace("{Publisher}", activity.Publisher.Name);

                //Then you will need to output the templateStr to the UI.
                //EncodedLiteral.Text += templateStr
            }


What you might notice is that you will get an "Null" Exception when you query the Publisher and the Owner properties of the ActivityEvent object. Stepping through the code, you will notice that the values will eventually load, and you will not get the exception. I'm not sure why this happens. If anyone knows, Feel free to leave a comment. A solution for this would be to get the TemplateVariable property and parse it as an XmlDocument object and then use that to get the Event values.

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.

Tuesday, November 24, 2009

Deploy Office Web apps on SharePoint 2010

Office Web Apps is the online companion to Word, Excel, PowerPoint and OneNote applications that allows users to access documents from virtually anywhere. Users can view, share, and work on documents with others online across personal computers, mobile phones, and the Web. Office Web Apps is available to users through Windows Live and to business customers with Microsoft Office 2010 volume licensing and document management solutions based on Microsoft SharePoint Server 2010.

To install Office Web Apps on your SharePoint Server 2010, read the following document for steps on how to deploy it. After deploying it to your SharePoint Server, users accessing your sites will be able to view, edit, and share documents from the web without the need to the Office client.


Other resources:

Integrated Windows Authentication with Claims Based Authentication in SharePoint 2010 error (IE)

Hi

In case you have a problem "signing as a different user" in SharePoint 2010 Web Application that uses "Claims Based Authentication" you will need to turn off the "Integrated Windows Authentication" option in Internet Explorer (As shown below). Without doing this, you wont be able to sign is as a different user.

This does not apply to other browsers and it is an IE issue.

Sunday, November 22, 2009

SharePoint Server 2010 Beta Key

In case you can’t find it on download page after registration page:

SharePoint Server 2010 Beta(Enterprise Client Access License features) product key:

PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY

BV7VC-RMR6B-26P6Y-BTQDG-DX2KQ

Both keys can be used. Feel free to post it elsewhere!

Friday, November 20, 2009

Enabling Taxonomy features on a Site Collection created using "Blank Site" template

When you create a new site collection in SharePoint 2010 using the "Blank Site" or "STS#1" site template, the Taxonomy feature (and possibly other features) will not be activated by default. It appears that Microsoft does not staple any features in the farm with the blank site template. This means, there is no way to activate the Taxonomy features in a blank site using the SharePoint UI because the Taxonomy features are hidden.

To activate the features, run the following stsadm command from the command prompt to enable the feature

stsadm -o activatefeature -id "73EF14B1-13A9-416b-A9B5-ECECA2B0604C" -URL "http://siteurl/sitecollection"

This will enable the "TaxonomyFieldAdded" feature on the team site which should bring the "Term Store Management" link in the site administration section of a site. This will also enable you to add the Managed Metada column to your lists and content types.

On a side note, the following features are related to the taxonomy in SharePoint
TaxonomyFeatureStapler
TaxonomyFieldAdded
TaxonomyTenantAdminStapler
TaxonomyTenantAdmin
TaxonomyTimerJobs

All the above features are "hidden" which means that you can't enable them from the SharePoint UI

Wednesday, November 18, 2009

FileNotFoundException error when installing SharePoint 2010 Beta





On a Windows Server 2008 R2 installation which passed all the prerequisites, you might get the following error :


11/17/2009 16:39:32 9 ERR Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.IdentityModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
at Microsoft.SharePoint.Administration.SPFarm.CurrentUserIsAdministrator(Boolean allowContentApplicationAccess)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Microsoft.SharePoint.Administration.ISPPersistedStoreProvider.DoesCurrentUserHaveWritePermission(SPPersistedObject persistedObject)
at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate()
at Microsoft.SharePoint.Administration.SPFarm.Update()
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RegisterDefaultDatabaseServices(SqlConnectionStringBuilder connectionString)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.Provision(SqlConnectionStringBuilder connectionString)
at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, IdentityType identityType, String farmUser, SecureString farmPassword, SecureString masterPassphrase)
at Microsoft.SharePoint.Administration.SPFarm.Create(SqlConnectionStringBuilder configurationDatabase, SqlConnectionStringBuilder administrationContentDatabase, String farmUser, SecureString farmPassword, SecureString masterPassphrase)
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnectConfigDb()
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


To resolve the problem you will need to download the following Geneva Framework version that had the required DLL.





Installing SharePoint 2010 Beta

Since SharePoint 2010 has been made available for MSDN/TechNet subscriber now, here’re some steps you would like to follow to get a successful installation. But keep in mind: This beta is not supported and you CANNOT upgrade the installation to RTM when it’s released. This Beta should only be used for evaluation purpose.


Follow these steps to install SharePoint Foundation 2010 and SharePoint Server 2010 Beta products. The process is split in two parts. The first part will install SharePoint Foundation 2010 Beta, and the second part will install SharePoint Server 2010 Beta. You can either install SharePoint Foundation 2010 or Start by installing SharePoint Server 2010.

before you start the installation, you will need the following pre-requisites

  • .Net Framework 3.5 with SP1 installed
  • Geneva Framework (Windows Identity Foundation) (download here)\
  • SQL Server 2005 SP3 and CU3 OR Server 2008 SP1 and CU2
  • Install WCF FIX: A hotfix that provides a method to support the token authentication without transport security or message encryption in WCF is available for the .NET Framework 3.5 SP1 (Windows Server 2008, Windows Server 2008 R2 – link not activated yet) . Please note the 2008 fix also applies to Vista, while the 2008 R2 fix also applies to Windows 7.
    If you don't have this fix installed, you will get "Unrecognized attribute 'allowInsecureTransport'" error in ULS log. And most of the service applications will not run properly
  • Create a special AD account that will be used as the SharePoint Managed Account in your farm. Refer to step 3 of the following post for how to create this account.
After you have applied the fixes and updates
  • Run the pre-requisite tool for SharePoint foundation 2010
  • After installing the binaries, run the configuration wizard. Setup the farm using complete farm installation. Use standalone installation only on Windows 7/Vista for dev purposes.
  • Go to Central Administration and run the "Configuration Wizards" to setup the service applications. Use a special user for the SharePoint Managed Account for services and web applications in the farm
  • Enable Developer Dashboard and turn to OnDemand for troubleshooting page performance issues. It can be done by STSADM or SharePoint 2010 Management Shell (Windows PowerShell).
    STSADM: stsadm -o setproperty -pn developer-dashboard -pv OnDemand
    Windows PowerShell:
    $svc=[Microsoft.SharePoint.Administration.SPWebService]::ContentService
    $ddsetting=$svc.DeveloperDashboardSettings
    $ddsetting.DisplayLevel=[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
    $ddsetting.Update()

After installing this, you will have SharePoint Foundation 2010/SharePoint Server 2010 installed.

External Links

Friday, October 30, 2009

Taxonomy Services, Managed Metadata, and Managed keywords

SharePoint 2010 comes with a new services that provides the functionality to tag content types with metadata and keywords. I will be posting more information about how to manage taxonomies within SharePoint 2010 in upcoming posts, for now, i will explain some keywords that we will see a lot in SharePoint 2010.

Taxonomy is a hierarchal tree of Values
Term Store is a DB containing different taxonomies
Term Set is a section in the term store that contains individual terms.
Term is a node in the taxonomy tree with an ID and many text labels
Tagging is the act of linking an item to a node or multiple nodes in the taxonomy tree.
Groups are security boundaries within the term store and above the term set.
Keywords are the actual links (reference) to a node in the taxonomy tree.
Managed Metadata Column is a new column type that can be added to content types
Managed Keyword Column is a new column type that can be added to any content type

At this point, i'm not sure what is the difference between the Managed keywords, and Managed Metadata.

These can be managed in SharePoint 2010 using the Term Management Tool. You will find this in Central Administration --> Manage Service Applications. The tool will allow administrators to publish, Terms, Term Sets, and importing them.

It is possible to tag documents within a desktop Rich Client such as MS Office Word.

---------------------------------------------

More Links

Tuesday, October 20, 2009

SharePoint 2010 UI Improvements

SharePoint 2010 has a lot of improvements in the UI which impacts the usability of the WCM in SharePoint in a positive way.

Some of the enhancements are:

  • Cleaner Markup: The Microsoft SharePoint Foundation (MSF) controls are no longer table based, and all the CSS classes were re-factored and cleaned up.
  • SharePoint 2010 is XHTML compliant, and also supports WCAG 2.0.
  • Reduced Postbacks / Page refreshes.
  • Server Ribbon, which copies the functionality of the ribbon in Office applications.

Metadata in SharePoint 2010

SharePoint 2010 comes with a huge taxonomy API, put into the Microsoft.Taxonomy.dll assembly.
With SP 2010, it is possible to tag items and pages with keywords from a term store, which then can be leveraged through the search solutions, or navigation solutions.

This will provide SharePoint with another method to visualize the data, together with the folder structure (i.e. SPSites, SPWeb, SPList approach).


SharePoint 2010 Developers Center


The SharePoint 2010 Developer Center is now live on MSDN. The site contains useful learning modules about SharePoint 2010. The site includes modules for getting started developing in SharePoint 2010.






Welcome to SharePoint 2010

Beta version of SharePoint 2010 will be released in November as announced by Steve Ballmer and Jeff Teper today at the SharePoint 2009 Conference.


The new version of SharePoint Office Server has a lot of new enhancements in regards to content management and collaboration. Some of the interesting new features are:
  • Social Feedback and Organization
  • Enterprise Metadata
  • Web Publishing including Digital Asset Management
  • Governance and Records Management
  • Development on Windows 7
and many more


For more details about SharePoint 2010, visit the SharePoint Team blog

Monday, July 13, 2009

Updating SPGroup owner

Hi

To update the owner of the group, you simply set the Owner property of the SPGroup object to a SPMember (which can be a SPUser or an SPGroup).

SPGroup spGroup = currentWeb.SiteGroups["GroupName"];
spGroup1.Owner = spGroup2;
sp.Group1.Update();

I was trying to update the owner of the SharePoint group through the API using the code above, but unfortunately that did not work.

So i did what most of the developers do, google it (i mean bing it). However i didn't find an answer to my question, so i tried to change my code and debug it until i found the solution.

For some reason, i had to get the reference to the SharePoint group from the root web of the site collection, rather than getting it from the web SiteGroups property.

so to fix the problem, i changed the above code to:
SPGroup spGroup = currentWeb.Site.RootWeb.SiteGroups["GroupName"];
spGroup1.Owner = spGroup2;
sp.Group1.Update();

I hope you will find this useful.