Wednesday, April 24, 2013

Customise List view webpart using custom XSL file in Sharepoint - 2013

I had this requirement of customising the XSLT list view webpart .Where in I had to redirect the users with few query string to a page.
Usually I used to go ahead with adding the List view webpart into the page by using the browser and edit the same page using the sharepoint designer later I would start editing the XSLT of the webpart using the design-->Edit XSLT view option in the designer .That does the job

But this time I tried to customise the XSLT by adding the cutom XSL file as link in the WebPart property of the List view webpart in the browser the Property name is "XSL Link".

Here are the steps how I achieved this
1)Create a blog site
2) Added a categories webpart as I wanted to customise this webpart .
3)Opened Visual studio and create new XSL file
4)Added the below code in the XSL file and saved it as testCustomise.xsl




<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
 <xsl:output method="html" indent="no"/>

 <xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">


  <xsl:variable name="TempSortedRows">
        <xsl:for-each select="/dsQueryResponse/Rows/Row">
          <xsl:sort select="@Title" order="ascending"/>       
    <xsl:copy-of select="."/>
   </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="SortedRows" select="msxsl:node-set($TempSortedRows)/*"/>
  <xsl:variable name="TotalRows" select="$SortedRows"/> 
    <xsl:call-template name="DisplayCategories">
   <xsl:with-param name="Rows" select="$SortedRows"/>
  </xsl:call-template>
 </xsl:template>

 <xsl:template name="DisplayCategories" ddwrt:ghost="" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
  <xsl:param name="Rows" />
        <ul>
   <xsl:for-each select="$Rows">
    <xsl:variable name="thisNode" select="."/>
    <xsl:variable name="catid" select="$thisNode/@ID"/>
    <xsl:variable name="catName" select="$thisNode/@Title"/>
    <xsl:variable name="targeturl" select="concat('Lists/Categories/Category.aspx?CategoryId=',$catid, '&amp;','Name=', $catName)" />
    <li><a href="{$targeturl}"> <xsl:value-of select="$thisNode/@Title" /></a></li> 
   </xsl:for-each>

  </ul>
 </xsl:template>
</xsl:stylesheet>


U can change the design using any HTML tags in "DisplayCategories" template name is the tag which describes how your design looks like in the webpage.You can go use any Coulmns I have made customisation to display only the Title  columns as anchor tag which will be redirected to categories page with few query strings .You can achieve any design or funcatinallity just by editing this XSL.


Later Since I was working in SharePoint-13 I placed the testCustomise.xsl in 15/Layouts/XSL .

Now You go back to browser

5)Edit Page-->Edit category List view webpart --> in the webpart property -->XSL Link
6)Add this /_Layouts/15/xsl/testCustomise.xsl
7)then say apply and ok

Now you should be able to see those styling changes with the hyperlink to different page


If you are workin in sharepoint 2010 place the file in 14 hive xsl your link will look as
/_Layouts/xsl/testCustomise.xsl


You could also place the file in site assets or site library and provide the XSL file link of the same to the webparts .That will work too !!



Wednesday, April 3, 2013

Localization [Multilingual fuctionality] of Infopath forms-13 for SharePoint 13 using XML a resource file

To creata a multilingual Infopath forms which is to be used in the Sharepoint site here are the below steps.

Software used are Infopath Forms 13 and Sharepoint 13

Open the Infopath form Designer select  a Blank form template.Publish it to the required sharepoint 13 site as content type or to form library .

Create an XML file called "Resource.xml" from which we pic the language specific text to to displayed in the Sharepoint site .

Your xml file can look like below :::


<?xml version="1.0" encoding="UTF-8"?>
<
LangSettings><
Languages><
Language Name="English" Code="ENG"/><
Language Name="Spanish" Code="SPA"/><
Language Name="French" Code="FRE"/></
Languages><
Labels><
Label Name="Name"><
LocalLabel Code="ENG" Value="First Name"/><
LocalLabel Code="SPA" Value="Nombre"/><
LocalLabel Code="FRE" Value="Nom"/></
Label> <
Label Name="Phone Number"><
LocalLabel Code="ENG" Value="Phone Number"/><
LocalLabel Code="SPA" Value="Ph no in Spanish "/><
LocalLabel Code="FRE" Value="Ph no in German"/></
Label> </
Labels><
Colors><
LocalColor ID="Blue" Code="ENG" Value="Blue"/><
LocalColor ID="Blue" Code="SPA" Value="Azul"/><
LocalColor ID="Blue" Code="FRE" Value="Bleu"/><
LocalColor ID="Green" Code="ENG" Value="Green"/><
LocalColor ID="Green" Code="SPA" Value="Verde"/><
LocalColor ID="Green" Code="FRE" Value="Vert"/><
LocalColor ID="Red" Code="ENG" Value="Red"/><
LocalColor ID="Red" Code="SPA" Value="Rojo"/><
LocalColor ID="Red" Code="FRE" Value="Rouge"/><
LocalColor ID="Yellow" Code="ENG" Value="Yellow"/><
LocalColor ID="Yellow" Code="SPA" Value="Amarillo"/><
LocalColor ID="Yellow" Code="FRE" Value="Jaune"/></
Colors></
LangSettings>

To add the XML file into the Infopath open the Infopath form-->DATA-->From Other Sources-->From XML files.

Browse the XML file and add it .Click finish for finish close the window for everything .

Below are the different scenarios in Infopath forms where the multilingual func has to be taken care of

First add a drop down list to select the required language of the forms.Use the resource as data source and select code as value field and Name as display field .

  1. LABEL
We are not going to use the  label here.Instead add a "Calculated field"

it opens in a pop up Pick the "Name " field to be displayed in such a way that add conditions like 
Display "Name " from resource file where "label=Name" and where "Code=Selected language"
the equation will look like below

@Value[@Name = "First Name" and @Code = LanguageChoice] 

2) For Drop Down display

use the resource file "color" field
Bind the drop down with the "color" tag of resource file and filter in such a way as to get only the data for partilar language .This is done by coparing with the selected language to ID field


3)For Button

There is no direct way with the button

You got to add 3 different buttons  for three different language having same id  but different display name
on clicking the each button add a rule to format the control
In the conditon
  •  Hide hide control
  • Condtion will be like "slected language  if not equal to ENG" same for other language too expect the last condition will be SPA or FRE

 

Monday, April 1, 2013

SharePoint-13 Multilingual for visual webparts

I had a requirement to create a multilingual visual webpart.The webpart has to be displayed in the language which is described by the browser.

Here is the way to achieve it in sharepoint 13 using the VS12

1)Create a empty sharepoint 13 solution Farm solution .
2) Add a sharepoin 13 project into it .
3)Add a mapped foder "Resources" to the project .
4)Now you gonna add three resources one for english "testMutliLing.en-US.resx" and one for german
    "testMutliLing.de-DE.resx" and one default  "testMutliLing.resx into the mapped folder.
5)In the designer of resource file add the key and value for both english and german resource file .

6)Now open the ascx file and add "label"
7)In the page load event add the following code

int id=1033;
//to get the default broweser language either "en-US" or "de-DE" etc etc


string a = HttpContext.Current.Request.UserLanguages[0].ToString();
if (a.Contains("en-US")){
id = 1033;
}

else{
id = 1031;
}
//german =1031 //english =1033
Label.Text =
SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)id);
}


The en-Us is equal to 1033 you get the different language codes for different languages if you browse for it in internet.

or you can even use

Label.Text = SPUtility.GetLocalizedString("$Resources:testMutliLing,String1", "testMutliLing",(uint)CultureInfo.CurrentUICulture.LCID);


Deploy the solution add the webpart to the page .

It shows the english version picking the value for "String1"  from english resource file.

to check for german .In IE goto internet options-->Languages-->add german de-DE and make it as default language by moving it to the top .say ok and refresh the page

Now the text for Lable is picked by "String1"  from the german resource file.


Also if you want to have multilingual markups you can use as below

<asp:Label ID="lbltest" runat="server" Text="<%$Resources:testMutliLing, String1; %>"></asp:Label>