March 29, 2012

SharePoint Designer: Search Web Part ‘Use Location Visualization’ breaks layout of search results

Problem

When using people search results web part, and wanted to modify the look and feel of the search results, one needs to uncheck the “Use Location Visualization” setting in Web Part properties.

image

When Location Visualization was checked, search results looked like this:

image

After unchecking the Location Visualization using SharePoint Designer, and without touching the XSL definition, search result looks like this:

image

As you can see, layout is far from what it should be.

Thoughts

Comparing the HTML of the two scenarios one can see that ID’s of several elements used in search results are different.

In correct layout scenario, IDs look like this:

image

However, in the broken scenario, IDs have some strange string appended to them:

image

Solution

As you might have guessed from my subtle highlighting, SharePoint Designer is causing this. When you uncheck the “Use Location Visualization” and save the page in SPD, SPD apparently notices that you have xsl:for-each loop that will end up in having multiple HTML elements with same ID. It then modified the ID fields and appends a generate-id() function to them.

image

You have two options:

  1. Only uncheck the “Use Location Visualization” using a browser and don’t modify the page with SPD after that.
  2. Modify the XSL after SPD has modified it and replace generate-id() with your custom variable, say $SPDRules, and define that as a parameter together with other parameters at the top of your XSL: <xsl:param name="SPDRules" />.

 

Technorati Tags:

March 28, 2012

SharePoint: Hide left navigation

Task

Hide left navi on a SharePoint site. I keep doing this almost daily and want a quick place to copy&paste the required style sheet from.

Solution for SharePoint 2010

Add this to CQWP, then set Web Part Chrome to None.
<style type="text/css">
body #s4-leftpanel { display: none; }
.s4-ca { margin-left: 0px; }
</style>



Solution for SharePoint 2013

Add this to Script Editor Web Part.
<style type="text/css">
#sideNavBox { display: none; }
#contentBox { margin-left: 20px; }
</style>



Technorati Tags:

March 26, 2012

Easily create Search SOAP Service Connection and a working search query

Task

How to easily create Search SOAP Service Connections in SharePoint 2010 Designer including a working query without getting all kinds of errors.

Solution

  1. Install FAST Search for SharePoint MOSS 2010 Query Tool (let’s just call it Query Tool)
  2. Install Fiddler 2
  3. Run the Query Tool and connect to your SharePoint by filling in site details and credentials and hit Get Metadata
    image
  4. If you’re not using FAST, you need to select SharePoint from the Results provider
    image
  5. Select the query scope and managed properties you wish to receive in search results
    image
  6. Start Fiddler
  7. In Query Tool, click Generate Query
  8. Back in Fiddler, on left side, select the search.asmx row, then on right side select Inspectors and TextView
    image
  9. Copy all text from TextView that is inside <queryXml> node
  10. Paste text in your favorite text editor and remove line breaks
  11. Paste the one liner into queryXml parameter value of your SOAP Data Connection in SharePoint Designer
    image
  12. All set! Use your new working data source as you wish.
Technorati Tags: ,,

March 23, 2012

SharePoint: Migrate from ActiveDirectoryMembershipProvider to SqlMembershipProvider

Task

In a SharePoint 2010 farm that was currently using Forms Based Authentication (FBA) towards Active Directory, there was a need to migrate users from Active Directory into SQL Server database. This needed to be done without having to modify user permissions on existing SharePoint sites, lists and items.

This migration needed also to be done without users noticing anything. What we specifically didn’t want to do was to create new user identities in SQL DB for all users, and send new passwords to all users via email. This would’ve technically worked just fine and it would’ve been straight forward procedure but it could’ve still raised some suspicion within users who would suddenly receive new passwords via email.

Solution

Migration from AD to SQL is done per user when user signs in. This is because at that time we have user’s password and can create an identical profile to DB. Flow chart below describes the logic.

image

In order for the user identity to remain same after migration, the new SqlMembershipProvider was created with same name as the previous ActiveDirectoryMembershipProvider, and ActiveDirectoryMembershipProvider was removed in web.config of the actual web site, SharePoint Central Admin and SecurityTokenServiceApplication.

So, before the migration, user identity was i:0#.f|myprovider|username, and after migration, as the name of the provider is identical, the identity remains as i:0#.f|myprovider|username. No need to modify SharePoint content permissions!

Note that you want to have password complexity rules defined in the SqlMembershipProvider so that on-the-fly migration succeeds. If DB is expecting more complex passwords that the user currently has in AD, migration of the user identity doesn’t succeed.

Also, you probably have more user profile properties in AD compared to what SqlMembershipProvider supports out-of-the-box, so you will need to implement custom user profile class that inherits from the ProfileBase class. In addition you will need to define the actual user object that contains the properties of the users you need to store. Example below.

public class UserProfile : ProfileBase
    {
        public static UserProfile GetProfile(string username)
        {
            return Create(username) as UserProfile;
        }

        public User User
        {
            get
            {
                return (base.GetPropertyValue("User") as User);
            }
            set
            {
                base.SetPropertyValue("User", value);
            }
        }
    }

    public class User
    {
        public User() { }

        public string FirstName { get; set; }
        public string LastName { get; set; }    
     }

Then you can access the user profile properties with the following code.

UserProfile profile = UserProfile.GetProfile(username);
User currentUser = profile.User;
currentUser.FirstName = "";
currentUser.LastName = "";
profile.Save();

 

Technorati Tags: ,

March 9, 2012

Codepage errors when creating installation package with WiX Toolset on Windows 8 CP

Problem

When trying to create Windows installation packages using WiX Toolset 3.5 on Windows 8 CP, you get errors like below.

A string was provided with characters that are not available in the specified database code page '1252'. Either change these characters to ones that exist in the database's code page, or update the database's code page by modifying one of the following attributes: Product/@Codepage, Module/@Codepage, Patch/@Codepage, PatchCreation/@Codepage, or WixLocalization/@Codepage.

Solution

This occurs when you’re using Visual Studio 2010, or Visual Studio 11 on Windows 8 CP that has specific Regional settings. If you’re using Finnish (Finland) regional settings, your Negative sign symbol is the culprit for this issue. Change Negative sign symbol to, e.g., -, and you’re good to go.

image

Technorati Tags: ,

March 2, 2012

Win8: Could not find usable certificate. Error: Element not found. 0x80070490

Problem


When trying to start Hyper-V virtual machine in Windows 8 CP, you get error

Could not find usable certificate. Error: Element not found. 0x80070490.

Thoughts


Restarting Windows doesn't help.

Solution


Check that your Hyper-V VMM service has generated a self-signed certificate required to run virtual machines.

Steps (from KB967902):
  1. Click Start , click Run, type mmc, and then click OK.
  2. On the File menu, click Add/Remove Snap-in.
  3. Click Certificates , and then click Add.
  4. Click Service account , and then click Next.
  5. Click Local Computer , and then click Next.
  6. Click Hyper-V Virtual Machine Management , and then click Finish.
  7. Click OK to close the Add/Remove Snap-in window.
  8. SEE BELOW! Expand Certificates - Service , expand vmms\Personal, and then click Certificates.
  9. SEE BELOW! Double-click the VMM Service certificate, and you should be able to view it's properties, such as expiration date.
If you don't see the Certificates folder under vmms\Personal, you don't have the required certificate.

Creating the missing certificate is easy:

  1. Open Hyper-V Manager
  2. Right click on the name of your local Hyper-V host machine
  3. Select Stop Service, then Turn Off
  4. Right click on the name of your local Hyper-V host machine
  5. Select Start Service
  6. Refresh the Certificate MMC window you hopefully still have open, and you will see the new certificate under vmms\Personal\Certificates, and you're good to go for the next 1000(!) years.