-->

Thursday, 12 January 2012

Get XML data from the CoreResultsWebPart

We often want to debug the XSLT code that we have written for our CoreResultsWebPart, this post will help you to extract the data from the CoreResultsWebPart and later which we can apply to debug our custom XSLT written for the CoreResultsWebPart.

Prerequisites

1. You need to have the Administrator privileges
2. Basic understanding of creating web applications and running the FAST search.

TODO

First thing you need to do is get the Basic Fast Search Center site up and running. Below i have mentioned the brief steps.
1. Create Web application with classic mode authentication.
2. Create a root site collection with "Fast Search Center" template.
3. Open the root site collection and try to search, as long as it displays the result you are fine :)

First Step : Edit the page and replace the default XSL with our custom XSL

As you Site is up and running, search for any term and go to the results page. Edit the page from Site Actions -> Edit Page
Search for the Search Core Results web part on the page and edit the web part. In the search core results editor pane, go to the Core Results->Display properties.

Uncheck the "Use Location Visualization" option, by default it would be checked.
Note: It means that site has to use the columns and XSL defined at the federated location level. Which is shared by all the search sites in the farm. When we uncheck this option we can define our own XSL format. More information on this topic can be found here
 
On unchecking this option the area under Fetched Properties and XSL editor will be enabled.
Fetched Properties are the columns that you want to be retrieved from the FAST search database. The columns mentioned within these properties will only be fetched.

Now click on the XSL editor button, it will open the dialog displaying the XSL used for the CoreResultsWebpart. Replace the default XSLT with the following code. Don't forget to take the backup of default code in case you want to revert back to original code :)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select="*"/>
</xsl:template>
</xsl:stylesheet>

 Click on Ok and save the page. 

Second Step : View the Search Results Web part XML data

Right-click the page zone that contains the Search Results Web Part that you want to view the search results XML data for, and then click View Source on the pop-up menu. This opens a page in Notepad that contains the HTML source. 


Search for the string “<All_Results>”. This is the opening tag for the section that contains the full search results set for the Web Part you modified.





Sunday, 30 October 2011

Enable PPS on Sharepoint Site

Lately I was integrating PPS into my SharePoint site and as normally we do I launched the PPS designer made some pretty nice charts. But when I deployed the PPS charts to SharePoint, It popped me up this error.
                “The SharePoint URL is a valid site but Performance Point Services features have not been configured. Please contact your site collection administrator for assistance”
Enable PPS on Sharepoint Site

After a lot of trial and error it blinked me that I had created the ‘Team Site’ instead of ‘BI site’, so none of the PPS libraries were imported at the time of site creation. Now I have been using the site for so long I can’t create a new one and start from the scratch. So I thought of creating the PPS libraries manually. But there was no content type defined for it.
About the time I was ready to start from the scratch Google came to rescue and I found some steps to create the PPS libraries. And I created add-on out of it. Following are the steps.
1.       Open Visual Studio and create a ‘Empty SharePoint Project’ from the SharePoint category and name it as ‘EnablePPS’

Enable PPS on Sharepoint Site


2.       Select the SharePoint site where you want PPS to be enabled and select the option of ‘Deploy as a Sandboxed Solution’ and click on Finish.
Enable PPS on Sharepoint Site

3.       Right click on the project and click on ‘add a new item’. Select the ‘Empty Element’ option and name it as ‘PPS Libraries’
Enable PPS on Sharepoint Site

4.       This will open the Elements.xml file. We will add the definitions of the PPS list that are required to enable the PPS.
<ListInstanceTitle="$Resources:ppsma,Onet_BICenter_Title"
Description="$Resources:ppsma,Onet_BICenter_Description"
TemplateType="450"
Url="Lists/PerformancePoint Content"
FeatureId="481333E1-A246-4d89-AFAB-D18C6FE344CE"
QuickLaunchUrl="$Resources:core,lists_Folder;/PerformancePoint Content/AllItems.aspx"
OnQuickLaunch="TRUE"/>
<ListInstanceTitle="$Resources:ppsma,Onet_BIDataConnections_Title"
Description="$Resources:ppsma,Onet_BIDataConnections_Description"
TemplateType="470"
Url="Data Connections for PerformancePoint"
FeatureId="26676156-91A0-49F7-87AA-37B1D5F0C4D0"
OnQuickLaunch="TRUE"/>
<ListInstanceTitle="$Resources:ppsma,Onet_BIDashboards_Title"
Description="$Resources:ppsma,Onet_BIDashboards_Description"
TemplateType="480"
Url="Dashboards"
FeatureId="F979E4DC-1852-4F26-AB92-D1B2A190AFC9"
OnQuickLaunch="TRUE"/>



5.       As you have created an empty element it will automatically create the feature under the ‘feature1’ as ‘Enable PPS’ and also create the package out of it.(Please see the below figure)
Enable PPS on Sharepoint Site

6.  In case, feature and packages are not created you have to create it manually.
7.  Although it has created the feature we need to add feature event receiver for it. So right click on the feature and click on ‘Add Event Receiver’. It will create the feature EventReceiver.cs file.
8.  It will have all the commented code of the ‘Feature Activated’, ‘Feature Deactivating’, ‘Feature Installed’, etc. We have to add our code into it to enable the PPS. Below is my code for the same


[Guid("71586fd1-7f8a-4607-a063-b6f5d688c158")]
publicclassFeature1EventReceiver : SPFeatureReceiver
    {
// Uncomment the method below to handle the event raised after a feature has been activated.
publicGuidPPSSiteMaster = newGuid("0b07a7f4-8bb8-4ec0-a31b-115732b9584d");
publicGuidPPSSiteCollectionMaster = newGuid("a1cb5b7f-e5e9-421b-915f-bf519b0760ef");

publicoverridevoidFeatureActivated(SPFeatureReceiverProperties properties)
        {
SPWeb web = properties.Feature.ParentasSPWeb;
SPSite site = web.Site;
if (site.Features[PPSSiteCollectionMaster] == null)
            {
site.Features.Add(PPSSiteCollectionMaster);
            }
if (web.Features[PPSSiteMaster] == null)
            {
web.Features.Add(PPSSiteMaster);
            }
        }

// Uncomment the method below to handle the event raised before a feature is deactivated.

publicoverridevoidFeatureDeactivating(SPFeatureReceiverProperties properties)
        {
SPWeb web = properties.Feature.ParentasSPWeb;
SPSite site = web.Site;
if (site.Features[PPSSiteCollectionMaster] != null)
            {
site.Features.Remove(PPSSiteCollectionMaster);
            }
if (web.Features[PPSSiteMaster] != null)
            {
web.Features.Remove(PPSSiteMaster);
            }
        }
    }



Congratulations!! We have prepared the add-on and now are we are ready to deploy the feature!!

Deploy the feature

1.       Right click on your project and deploy to our SharePoint site where you want to enable the PPS.This will deploy the WSP package in the SharePoint site.
2.       In my case it automatically activated the feature on deploying, Incase it’s not activated go the ‘Manage Site Features’ from the ‘Site Settings’ page of your SharePoint site. It would have listed the ‘Enable PPS’
3.       When deploy is succeeded, Open the site and go the list and libraries of the site. You will find a new list created with the name ‘Performance Point Content’
4.       Now go to your DDWX file and try deploying the PPS chart again. It should be done smoothly now.

Wednesday, 17 August 2011

Fault Contracts in WCF services

Recently I was asked to raise a custom exception in the WCF Services which will be handled on the client side. As a normal programmer I created a custom exception in my service and left on the client side to handle. Assuming that it will be sent on the client side as it is. Instead it showed me this error.
Fault Contracts in WCF services

Little as I knew, something clicked me that if we pass/return the custom objects it has to be defined as a contract. As contracts are the only thing that WCF uses to communicate with the client.
I googled a bit around and came with the concept of Fault Contracts. Consider I have created a custom exception class as defined below
[DataContract()]
    public class CustomException
    {
        [DataMember()]
        public string Title;
        [DataMember()]
        public string ErrorMessage;
        [DataMember()]
        public int ErrorCode;
        [DataMember()]
        public string StackTrace;       
    }

Now if I throw this exception directly to the client, it would not recognize it. Hence any method which can raise this exception should specify the attribute while defining it. (as shown below)
[ServiceContract()]
    public interface IService
    {
        [OperationContract()]
        [FaultContract(typeof(CustomException))]
        String MyMethod(string inputParams);
    }
The next step is throwing the exception from the method
public String MyMethod (string inputParams)
        {
        CustomException error = new CustomException();
        error.Title = "my custom exception for fault contracts";
        error.ErrorMessage = "Error in MyMethod";
        error.ErrorCode = 1001;
        error.StackTrace = "custom stack trace";
        throw new FaultException(error,"Reason: Testing the Fault contract");
        }

While on the client side , you can catch the thrown exception as shown below,
        try
        {
        Proxy.MyMethod(“Kalashnikov”);
        }
        catch (FaultException<MyService.CustomException> ex)
        {
        //Process the Exception as thrown
        }

Custom Login page for Sharepoint 2010 Mixed mode authentication

In one of my previous post, I discussed about adding form authentication to your SharePoint site. I Hope it was useful ! This post is dedicated to customize the Login Screen for the SharePoint site


Recently I had to configure Windows authentication and forms authentication in SharePoint 2010. It should not have been difficult in 2010 as it have mixed mode authentication. But what lacked were enough tutorials/articles. So I thought to share it!
First of all we need a landing page for our application. It is good to have common landing page for windows authentication and SharePoint authentication. So that every unauthenticated request can be re-directed to single page. By default SharePoint have a dropdown to select the authentication mode and then proceeds based on selection.
Custom Login page for Sharepoint 2010 Mixed mode authentication
We can also have our own login page with the same functionality. I have designed something like this.
Custom Login page for Sharepoint 2010 Mixed mode authentication

You have to specify the login page URL in web.config. By default it is “/_login/default.aspx”
<forms loginUrl="/_layout/MyLoginPage.aspx" />
Note : MyLoginPage.aspx should be application page as user will not have access to SharePoint page,  as he /she is not authenticated yet.
As now as we have our login page ready, we need to add the code for login button and hyperlink to intranet access
1.       Forms Authentication via Login Button
2.       Windows Authentication via hyperlink ‘Click here for intranet access’

1.       Forms Authentication
In the event handler of login click event we can authenticate the user with the following method.
SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer,
                   Username,
                          Password);
This method authenticates a form user by checking username and password. When the user is validated this object persists a cookie to the client for later use.

2.       Windows Authentication
LnkIntranet.NavigateUrl = Page.ResolveUrl(@"~/_windows/default.aspx?ReturnUrl=/YouLandingPage.aspx");

SharePoint will authentication the windows logged in user
On Success it will redirect to the ‘ReturnUrl’ page mentioned in the parameter
On Error it will redirect to ‘AccessDenied.aspx’

Tuesday, 14 June 2011

Difference between Sharepoint List and Document Library

Difference between Sharepoint List and Document Library


• In to a document library we can upload document which are not blocked file type and some content, which get stored in Content database. A list on the other hand a just piece of data, just like SQL table although it is possible to store binary content in to list as well as using attachment.
• And with a document library we can SPFileCollection.add(string, stream) – Document Library Accept a stream, means the content can be in memory, or disk or even a TCP/IP socket.
• But with List we Only Can SPAttachmentCollection.Add(string, byte) only accepting a byte , means the attachment must fit entirely in one continuous block memory. It this is something you do with large file , your server memory may become fragmented
• And we Can Publish a InfoPath Form Template in document Library, and this problem is rise when we submit the Form in different place then where you published the form.
• We can’t create Folder in List but we can create in Doc. Library
• Document library the Check in Check out functionality but not in List.
• Document library support the Major and Minor Version of files and Folders. But in List only support the Major version. So that two people cannot change the same content at concurrently.
• Some type of list have different functions like for instance people being only able to read their own posts, but these are not available in every type of list and are not available at all with document libraries and other libraries.
• List have one special List Content type, same as list Library has also Document Library type content type.
• Both list and Library are support Event handler and Workflow like features.

Saturday, 16 April 2011

Change the windows authentication to Form Based authentication for SharePoint 2007 Site




I am assuming  that you have already created a SharePoint site on your machine which is already running with a windows authentication as it is requires minimum configuration to start with. If you don’t have a site running on windows authentication you can create it using the following link
We will split our tutorial in 6 steps as below.
Step 1: Create SQL Server Database for membership
Step 2: Adding user to the database.
Step 3: Web.config Modifications
Step 4: Add newly created user to the SharePoint site
Step 5: Enable the “Forms” Authentication
Step 6: Run the application

Step 1: Create SQL Server Database for membership


To enable Form based authentication, we need to have a database to store the user information such as user credentials, roles associated, etc. To create the database Microsoft has provided a utility which creates a database for us. Utility can be found here %windir%\Microsoft.Net\Framework\vx.x.xxxxx on your server. Refer the image below.
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Run the aspnet_regsql application and it will start the ASP.net SQL Server wizard. Refer the image below
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Click Next >
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Select the first option “Configure SQL Server for application services” and then click next >
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

It will display the server name. Select the proper Authentication and Database (I have kept it at default aspnetdb) Click Next >
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

It will start creating the database “aspnetdb” in your SQL Server and required tables, store procedures for user membership. Click on finish and exit the wizard.
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

You can open SQL Server to check if the database is created and what tables/Store Procedures wizard has created.
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Step 2: Adding user to the database.

We have all the necessary stored procedure to create new user in the database. Using these procedures we can create our custom user interface to add user to the database or we can use the membership seeder tool provided by Codeplex
For simplicity, We will use these tool to create user. Extract the download folder  and execute the MembershipSeeder.exe file
Enter the username, password, email address in the screen as shown below
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Currently we have to create just one user so don’t forget to check the “Only create or delete 1 user; don’t user the # of users field” Else it will create 50 users with the prefix specified in the User Prefix.
Click on Create Button and it will add the user in the aspnetdb. To check if user has been added, you can execute the following query on the table “aspnet_Users”
SELECT  [UserName]
      ,[LoweredUserName]
      ,[MobileAlias]
      ,[IsAnonymous]
      ,[LastActivityDate]
  FROM [aspnetdb].[dbo].[aspnet_Users]

Step 3: Web.config Modifications

Following changes has to be made din web.config file of the site. Open the web.config of the SharePoint site you want to change the authentication to Forms.
Add the following connection string in the <connectionStrings > part of the file.
<add name="fbaSQL" connectionString="server=localhost;database=aspnetdb;Trusted_Connection=true" />

Replace the localhost with the database server name if Databaser server is hosted on other  machine.
Replace the aspnetdb with the database name you specified in Step 1.

Add the following Lines in the <system.web> part of the file.
<membership  defaultProvider="fbaMembers">
      <providers>
        <add connectionStringName="fbaSQL" applicationName="/" name="fbaMembers" type="System.Web.Security.SqlMembershipProvider, System.Web,&#xD;&#xA;          Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </membership>

Note : Do not forget to specify the “deafultProvider” attribute in the membership tag
Add the following line inside the <PeoplePickerWildcards> tag
<PeoplePickerWildcards>
      <clear />
      <add key="AspNetSqlMembershipProvider" value="%" />
      <add key="fbaMembers" value="%" />
    </PeoplePickerWildcards>

Step 4: Add newly created user to the SharePoint site.

Go to the application and make sure that site is running in Windows authentication.
Go to the setting s page http://<Sitename>/_layouts/settings.aspx  of the site.
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Click on “Advanced Permissions” -> Click on “New” -> “Add Users”
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

It will open the Add User screen. Enter the username you created in the step 2 and click the people picker button, It will find user. Refer the image below
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Give him the required permissions and then click on Ok. Your user will be added to the sharepoint site.

Step 5: Enable the “Forms” Authentication


Open the web.config file of the site. Search for the tag “authentication”. It would be running in “Windows” authentication. Change it to “Forms” and add the <forms loginUrl="~/_layouts/login.aspx"/> in it.
Your authentication tag should look like  below
<authentication mode="Forms" >
      <forms loginUrl="~/_layouts/login.aspx"/>
    </authentication>

Step 6: Run the application

Open the site. It will redirect you to the SharePoint default login page as shown below
Change the windows authentication to Form Based authentication for SharePoint 2007 Site

Enter the required credentials and click on “Sign in”. It will redirect you to the SharePoint site with the logged in user as “Dhaval”
Change the windows authentication to Form Based authentication for SharePoint 2007 Site


Congratulations! Your site is running in the Form Based Authentication mode.
More Features:
As we are done with the basics of FBA, you can further explore more features of the FBA,
  1.  Create your own custom membership so that you can override the “ValidateUser” method to do custom validation on the SharePoint.
  2.  It is not necessary to use the separate database for Forms authentication. You can use the same existing database of your application. You just need to add the required tables in your application database. The script files can be found under %windir%\Microsoft.Net\Framework\vx.x.xxxxx of your server.