Monday, October 28, 2013

SharePoint 2013 WorkFlow +System.ServiceModel.ServerTooBusyException:

System.ServiceModel.ServerTooBusyException:

Found this error while trying to publish List WF from designer .Many post suggest while googling that you can increase the "QUEUE Length" of the particular process in IIS for particular application pool.

But for me a System restart did the magic
 

Sharepoint 2013 reports + An unexpected error occurred while connecting to the report server. Verify that the Reporting Services Service Application mapped to this web application is available OR the report server is available and configured for SharePoint Integrated mode

An unexpected error occurred while connecting to the report server. Verify that the Reporting Services Service Application mapped to this web application is available OR the report server is available and configured for SharePoint Integrated mode. --> The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>IIS 8.0 Detailed Error - 500.19 - Internal Server Error</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}
code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}
.config_source code{font-size:.8em;color:#000000;}
pre{margin:0;font-size:1.4em;word-wrap:break-word;}
ul,ol{margin:10px 0 10px 5px;}
ul.first,ol.first{margin-top:5px;}
fieldset{padding:0 15px 10px 15px;word-break:break-all;}
.summary-container fieldset{padding-bottom:5px;margin-top:4px;}
legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}
legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;
font-weight:bold;font-size:1em;}
a:link,a:visited{color:#007EFF;font-weight:bold;}
a:hover{text-decoration:none;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0'. --> The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>IIS 8.0 Detailed Error - 500.19 - Internal Server Error</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}
code{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}
.config_source code{font-size:.8em;color:#000000;}
pre{margin:0;font-size:1.4em;word-wrap:break-word;}
ul,ol{margin:10px 0 10px 5px;}
ul.first,ol.first{margin-top:5px;}
fieldset{padding:0 15px 10px 15px;word-break:break-all;}
.summary-container fieldset{padding-bottom:5px;margin-top:4px;}
legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}
legend{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;
font-weight:bold;font-size:1em;}
a:link,a:visited{color:#007EFF;font-weight:bold;}
a:hover{text-decoration:none;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0'. --> The remote server returned an error: (500) Internal Server Error.



Found this error when tried to use the Report Viewer webpart in SharePoint 2013 page after the "REPORT SERVICE was configured in SHAREPOINT INTEGRATED MODE"


Solution: Run the SP1 for SQL server 2012

Problem: the report viewer try to access web service from this location -->C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\WebServices\Reporting

But if you have not applied SP1 for SQL2012 you will find this Reporting folder only in 14 Hive not in 15 hive. After the update of Report service in SharePoint integrated mode from SP1 you will  be able to see the Reporting folder in 15 Hive too.


For Report to work in SharePoint integrated mode in SharePoin 2013 SP1 for SQL 2012 is very much required

Sharepoint 2013 workflow + The server was unable to process the request due to an internal error


RequestorId: 321d7a5c-ca52-907e-0000-000000000000. Details: RequestorId: 321d7a5c-ca52-907e-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 401 {"error_description":"The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."} {"x-ms-diagnostics":["3001000;reason=\"There has been an error authenticating the request.\";category=\"invalid_client\""],"SPRequestGuid":["321d7a5c-ca52-907e-aab4-69867fb6c2f8"],"request-id":["321d7a5c-ca52-907e-aab4-69867fb6c2f8"],"X-FRAME-
":["SAMEORIGIN"],"SPRequestDuration":["64"],"SPIisLatency":["3"],"Cache-Control":["private"],"WWW-Authenticate":["Bearer realm=\"3eafb22a-93a3-48a8-9c32-16829fce2722\",client_id=\"00000003-0000-0ff1-ce00-000000000000\",trusted_issuers=\"
00000005-0000-0000-c000-000000000000@*,00000003-0000-0ff1-ce00-000000000000@3eafb22a-93a3-48a8-9c32-16829fce2722\"","NTLM"],"X-AspNet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"MicrosoftSharePointTeamServices":["15.0.0.4481"],"Date":["Mon, 28 Oct 2013 10:49:09 GMT"]} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)



I found this error when I attached a designer List workflow and tried to start the workflow

Solution: Your User Profile Sync Service Should be running .If not add the user to the "Manage User " of User Profile server ,this is the user who triggers the workflow


Basic principle behind this is every user triggering the WF should have a profile of him in User Profile Application Service.

 

Wednesday, October 16, 2013

Connect custom webpart to List View Webpart in SharePoint 2013 .Connected Webparts send parameter from Custom webpart

I had a requirement to sending a parameter from custom webpart and sending it to a report view webpart .This code can also be used to connect any custom webpart with List view webpart.

All you need to do is
1)Open visual studio
2)Create a project
3)Using the template "Webpart" which is grouped under Sharepoint section in VS create a item
named "FilterWebpart".

Use the below code in FilterWebpart.cs



using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Collections.ObjectModel;

namespace ProviderWebpartVS.FilterWebpart
{
    [ToolboxItemAttribute(false)]
    public class FilterWebpart : System.Web.UI.WebControls.WebParts.WebPart, ITransformableFilterValues
    {

        string propertyvalue = "BSW3";     

        #region ITransformableFilterValues Members

        public bool AllowAllValue
        {
            get { return true; }
        }

        public bool AllowEmptyValue
        {
            get { return true; }
        }

        public bool AllowMultipleValues
        {
            get { return false; }
        }

        public string ParameterName
        {
            get { return "ConnectionProperty"; }
        }

        public System.Collections.ObjectModel.ReadOnlyCollection<string> ParameterValues
        {
            get
            {
                string[] values = new string[] { propertyvalue };
                return new ReadOnlyCollection<string>(values);
            }
        }

        [ConnectionProvider("Connection Property Filter", "ITransformableFilterValues", AllowsMultipleConnections = true)]
        public ITransformableFilterValues SetConnectionInterface()
        {
            return this;
        }

        #endregion
        protected override void CreateChildControls()
        {
        }
    }
}

4)Now deploy the solution into a sharepoint site.
5)Open the site in browser 
6)Add this custom webpart .
7) Also add report view webpart which has parameters or any other list view webpart
8)Edit the webpart -->click -->Connection -->Connect to any webpart on the page.A configuartion window popups on the page where you can configure which parameter is connected to which webpart.


9)Here in this example propertyvalue will be sent as parameter to other webpart.You can change it to take arrary of string in "string[] values"  as shown in code.You your custom logic here to fill the data into string[] values.



Thanks to links below which helped in achieving this

http://blogs.msdn.com/b/edhild/archive/2007/03/28/how-to-build-a-custom-filter-provider-web-part.aspx














Wednesday, October 9, 2013

SharePoint 2013 "Developer Dashboard" configuration and usage

Enabling the SharePoint 2013 "Developer Dashboard" is quite simple
There is no difference between the 2010 version and 2013 version of SharePoint

Below are the steps to enable it.

  • Log on to server where the SharePoint is Installed
  • Open  SharePoint Management Shell
  • Use the below code


 $devDash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
 $devDashSetting = $devDash.DeveloperDashboardSettings
 $devDashSetting.DisplayLevel = "On"
 $devDashSetting.Update()



The only difference between the SharePoint 2010 and SharePoint 2013 is that there is only two state now
  1. "On"
  2. "Off"

In SharePoint 2010 you had a state name "OnDemand" too which is deprecated in this version
After execution of this command you can open any off your SharePoint site in the farm .You will see a link at the right top corner in the master page.

Click on the link It may not work sometime !!
The reason behind it is your farm may not  have the "Usage and Health Data Collection Service Application"

Create a new 
"Usage and Health Data Collection Service Application" through central Admin site or through
Powershell
In Sharepoint 2013 the data in Developer tool is synced with Usage and heath data collection Service database.Hence this service application should be up and running to use the Developer DashBoard

Now come back to the site.Click on the  developer Dashboard Link.
You can notice that a seperate window is getting opened  this is nothing but your new Developer DashBoard

Advantage of this is that this console is not integrated with in the site as in SharePoint 2010 did,hence by reducing the time delay to open the page.You also see that this has many more options like
  • Better UI
  • Better segregation of data
  • ULS viewer-You may use this to check logs rather than separately relying on other ULS viewers
  • You can also have a better refined way look at each methods and query hit to the database.




Wednesday, September 25, 2013

This page allows a limit of 200 controls, and that limit has been exceeded in SharePoint

I was working on custom New form which I had created in Visual Studio 2012 as aspx page and attched it to the list.
I had large number of controls in the page and found this error when i tried to browse it through browser.

The solution for this error was to change a setting in web.config.

Here I am working on SharePoint 2013

So I went to

C:\inetpub\wwwroot\wss\VirtualDirectories\

Now open webapplication Eg:80 where your site is hosted

open web.config

Find the tag below in the web.config

 <SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="250" AllowPageLevelTrace="false">  


by default  MaxControls="200" is set to 200.So you get the exception.

You can change this according to your requirement.

This is resolve the issue.

Friday, September 20, 2013

Visual Webpart on Text Box Change event Append the Text box data with Check Box list and Drop down Selected Value

Below is the code in which on you type in something on text box and on tab event(On change) event of text box the slected values from Check Box list and drop down is appended with text and displayed in Multiline text box control


In your ascx page use below code


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>


<script type=text/javascript>
    function AutoFill() {
       
        var chkSelectedLang = new Array();
        var i = 0;
        $('#<%=chkList.ClientID %> input[type=checkbox]:checked').map(function () {
         
            chkSelectedLang[i] = this.value;
            i = i + 1;

        });
       
        //var string1 = "";
        //for (var i = 0; i < myLanguage.length; i++) {

        //    string1 += myLanguage[i] + ";";
        //}       
        //alert(string1);       
        //alert(drop);
        var publicationNo = "";
        var materialNo = $("#txtMaterialNo").val();
        var ddlSelectedLang = $("#ddlLang").val();
        publicationNo = materialNo + ddlSelectedLang + ',' + '\n';
        for (var i = 0; i < chkSelectedLang.length; i++) {
            publicationNo += materialNo + chkSelectedLang[i] + ',' + '\n';
        }
        $("#txtMultiLine").val(publicationNo);
    }
</script>




<div style="border:1px solid black">
    <asp:CheckBoxList ID="chkList" runat="server">
        <asp:ListItem Value="I">India</asp:ListItem>
        <asp:ListItem Value="U">USA</asp:ListItem>
        <asp:ListItem Value="E">England</asp:ListItem>
    </asp:CheckBoxList>

</div>

<div style="border:1px solid green">
    <asp:DropDownList ID="ddlLang" ClientIDMode="Static" runat="server">
        <asp:ListItem Value="I">India</asp:ListItem>
        <asp:ListItem Value="U">USA</asp:ListItem>
        <asp:ListItem Value="E">England</asp:ListItem>
    </asp:DropDownList>
</div>

<div style="border:1px solid red">
<span>Material No</span><asp:TextBox ID="txtMaterialNo" ClientIDMode="Static" runat="server" onChange="AutoFill()" ></asp:TextBox>
<asp:TextBox ID="txtMultiLine" ReadOnly="true" ClientIDMode="Static" runat="server" TextMode="MultiLine"></asp:TextBox>   
</div>


Also Find the demo at the below link
Thilosh-Fiddle




Tuesday, August 27, 2013

SharePoint Event receiver triggering for all list .Need to trigger for only one list or one type of list

Hi one of the most common requirement in SharePoint is to have event receiver attached to a list .But when you add a event receiver item in Visual Studio and deploy .It will be attached to all the list .

Below are the few things you need to follow to attach a Event Receiver to particular list in SharePoint

1)In the Element.xml of Event Receiver change the tag property as below

         <Receivers ListUrl="Lists/List1">

This will attach the Event Reciever to only List1


2)Changing the tag as below

        <Receivers ListTemplateId="10001" >

will attach the Event Receiver to all the list in site which as listTemplateID =10001

These id are found when you create a list definition by yourself through Visual Studio.
Follow  this link Default list template Id to know about default list id of share point list.


Even after doing this few people see that Event Receiver is been attached to all the list .

The main reason for this is the Feature which is trying to activate the Event Receiver is at Site scope it has to be always at Web scoped . If it at Site scoped the ListUrl and ListTemplateId will be overridden and it will be attached to all the list in the site.

Monday, August 19, 2013

Add data to people picker in Visual webpart programatically - sharepoint 2010

Add the People picker field in the ascx file as below

 <SharePoint:PeopleEditor runat="server" ID="peoplePickerID" MultiSelect="true" 
SelectionSet="User" />

in the code behind on page load write the logic to fill teh people picker from a list having a
people/group type column.


ArrayList PickerEntities = new ArrayList(); 
SPFieldUserValueCollection fieldUserValueCollection = (SPFieldUserValueCollection)item["PeopleGroupTypeColumnDispName"];

            foreach (SPFieldUserValue spuserval in fieldUserValueCollection)
            {
                SPUser userToassign = spuserval.User;
                PickerEntity entity = new PickerEntity();
                PeopleEditor pepEditor = new PeopleEditor();
                entity.EntityData["AccountName"] = spuserval.User.LoginName;
                entity.EntityData["SPUserID"] = spuserval.User.ID;
                entity.EntityData["Email"] = spuserval.User.Email;
                entity.Key = spuserval.User.LoginName;
                entity.Description = spuserval.User.LoginName;
                entity.DisplayText = spuserval.User.Name;
                entity = pepEditor.ValidateEntity(entity);
                entity.IsResolved = true;
                PickerEntities.Add(entity);
            }

peoplePickerID.UpdateEntities(PickerEntities);

 *item["PeopleGroupTypeColumnDispName"];--> is list column of people/group type


Have a look at other post about client people picker of Sharepoint 2013
Client people picker-Sharepoint 2013 



 

Wednesday, August 7, 2013

SharePoint 2013 Workflow

The concept of Workflow in SharePoint 2013 is changed a whole lot.

The three thing which you need to take care while configuring the workflow to run on SharePoint 2013 is that

  1. Workflow Manager 1.0
  2. Workflow client 1.0
  3. Workflow Manager Tool for Visual 2012
  4. Developer Tools for Visual studio.

As the Workflow does not run inside the share point  you can install Workflow Manager 1.0  on different server or on same server where share point is hosted ..You can follow the MSDN link below to install and configure the Workflow Manager 1.0.

http://technet.microsoft.com/en-us/library/jj658588.aspx

Workflow client 1.0 - This has to be installed on all the sharepoint server (Web fornt end,App).This has API which communicates with the Workflow Manager.

Workflow Manager Tool for Visual 2012 - This has to be installed on the server where you create Visual studio 2013 SharePoint Workflow.Assuming that VS2012 is already installed .
2013 Sharepoint WF template is named as "Workflow"  in VS the "sequential and state machine" template is legacy now and it is not used in SharePoint 2013.

Developer Tools for Visual studio- Is to be installed on server where the Visual studio 2012 is installed.This provide new activities in Tool Box of VS12.


Along with this when you try to install the WorkflowManager through webPlatform installer .
Service Bus and cummunlative updates will be installed automatically.If you are installing it manually you need to install all the updates and Service bus.


Even after having all this there will be few problem with sending mails from VS12 WF.To overcome the issue You need to Install the MARCH-PU sharepoint 2013 updated and configure the same.


Plese follow the below link to install and configure it

http://www.deliveron.com/blog/post/Installing-March-2013-Public-Update-on-SharePoint-Server-2013.aspx


After all these are done you also need
  • App Management Service to be running
  • User Profile Service to be running
  • User Profile Sync Service to be running
Only then your WF runs without any problem :)

Tuesday, July 30, 2013

Add data from People Picker control into people/Group column field of a list in Sharepoint Visual Webpart

The below code can be used in visual webpart where in you have a requirement to pick the data from people picker field and add the data to people or group column of any list


 SPFieldUserValueCollection customer = new SPFieldUserValueCollection();
                    foreach (PickerEntity enity in pepPickCustomer.ResolvedEntities)
                    {
                        SPUser user = SPContext.Current.Site.RootWeb.EnsureUser(enity.Key);
                       
customer .Add(new SPFieldUserValue(SPContext.Current.Site.RootWeb, user.ID, user.Name));

                    }

Later to add data to list

item["PeopleGroupColumName"] = customer;


*
pepPickCustomer is the ID of Client people picker control which is a new type of people picker control available Sharepoin 2013.

Thursday, July 25, 2013

Run all Powershell Scripts through batch file (.dat)

If you have many powershell scripts and you want to run all of those in a single click deployment
then use the below technique


1)Create a batch file  named "StartFile.bat"
2)Create a powershell script "PowershellFile.ps1" and add all your code in it
3)Edit the "StartFile.bat" and add the below piece of code



cd /d %~dp0
powershell.exe -File
PowershellFile.ps1
pause


4)Now save the changes
5)Run the batch file as Admin.
6)Your powershell script will be run



------------------------------------------------------------------------------------------------------------cd /d %~dp0
will open the powershell.exe from current location where the whole folder consisting of batch and powershell file is placed in a folder.

Friday, July 5, 2013

Add data to People picker field programatically -Sharepoint 2013

I had a requirement where in the visual webpart had a people picker control .I used the client people picker which is a new and betta control in Sharepoint 2013.This control had to be binded with the data coming from a people picker field of some list.Here is the code to achieve it




SPFieldUserValueCollection reviewers = (SPFieldUserValueCollection)Item["PeoplePickerFieldColumnDisplayName"];
List<PickerEntity> reviewersEntity = new List<PickerEntity>();
foreach (SPFieldUserValue spuserval in reviewers){

SPUser userToassign = spuserval.User;
PickerEntity entity = new PickerEntity();
PeopleEditor pe = new PeopleEditor();
entity.EntityData["AccountName"] = spuserval.User.LoginName;
entity.EntityData["SPUserID"] = spuserval.User.ID;
entity.EntityData["Email"] = spuserval.User.Email;
entity.Key = spuserval.User.LoginName;
entity.Description = spuserval.User.LoginName;
entity.DisplayText = spuserval.User.Name;
entity = pe.ValidateEntity(entity);
entity.IsResolved =true;
 reviewersEntity.Add(entity);
}
PeoplePickerControlName.AddEntities(reviewersEntity);



*"item " is a SPListItem type


in ascx file client people picker looks like

<SharePoint:ClientPeoplePicker runat="server" ID="PeoplePickerControlName" Required="true" ValidationEnabled="true"
                        InitialHelpText="text"
                        VisibleSuggestions="3"
                        Rows="1"
                        AllowMultipleEntities="true"
                        CssClass="ms-long ms-spellcheck-true" /> 

Have a look at other post about  people picker of Sharepoint 2010
People Picker -Sharepoint 2010 

Monday, June 17, 2013

Get data from People Picker(ClientPeoplePicker) through code

There is a new control in sharepoint 2013 named ClientPeoplePicker.Which is a very good control loads the user prediction on the client side using a hidden div .


To get the data from this control on the server side use the code below


string a = "";

ArrayList resolve = pepPickcker.ResolvedEntities;
foreach (PickerEntity entity in resolve){
a += entity.Key+";";   //Key will give you the login name you can use other attributes}


*pepPickcker is the control ID


Friday, June 14, 2013

Get the details of features in sitecollection in sharepoint

open the Sharepoint management shell and use the code

Get-SPSite hhtp://yoursitecollection | Get-SPWeb -Limit ALL | %{ Get-SPFeature -Web $_ } | Sort DisplayName -Unique | FT DisplayName,Id

Monday, June 10, 2013

Multilingual markups in aspx pages

You can use the below tag to have a multilingual texts in aspx pages

Text="<%$Resources:testresourcefile, lbltest; %>"

Where testresourcefile is the default resource file name and lbltest is a key in all the resource files .

you got to have Resource files

  •  testresourcefile.resx
  • testresourcefile.en-US.resx
  • testresourcefile.de-DE.resx
  • etc
in Mappaed foledr called "RESOURCES" in your visual studio project.



for other multinguals

Infopath forms
Visual Webparts
Site columns,Content types and lists

Wednesday, June 5, 2013

Create Multilingual Sharepoint Site Columns,Content types and Lists from Visual studio programatically




·         Create resource file Eg: test.resx ; test.en-US.resx for English and  test.de-DE.resx for German
·         Add the key values Eg: Stringtest = Documan
·         Create site columns
·         Change the display name of site columns in element.xml as DisplayName="$Resources:Stringtest" Note:Stringtest should be in all the above resource files.
·         Now since your site columns are create in multilingual.
·         Create content type using these columns.
·         In the content types element.xml also do the same leave the FieldRef “id” “name” same but change the displayname as Eg ( DisplayName="$Resources:Stringtest ")
·         Now create the list using the content type .You the change the list definition and instance also in the same way as specified above
·         You can now deploy and check everything will be multilingual.


But Please note that these resource files should be added to the sharepoint MAPPED RESOURCE folder and also open you feature property and change the “default resource file “ to “test
As our default resource file name in test

Thursday, May 30, 2013

Sharepoint pop up window from code behind in visual webparts

You can use the below piece of code to open a sharepoint pop up window from code behind .This is done by calling a jaavascript function on button click from the code behind

In the ascx page use the below code
<script type="text/javascript">
function OpenDialog(strPageURL, width, height, title, args) {
ExecuteOrDelayUntilScriptLoaded(test, "sp.js")
function test() {
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = strPageURL; // URL of the Page
dialogOptions.width = width; // Width of the Dialog
dialogOptions.height = height; // Height of the Dialog
dialogOptions.title = title;
dialogOptions.args = args;
dialogOptions.allowMaximize =
false;
dialogOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
// Function to capture dialog closed event
SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
return false;}
}


// Dialog close event capture function
function CloseCallback(strReturnValue, target) {

if (strReturnValue === SP.UI.DialogResult.OK) // Perform action on Ok.
{//alert("User clicked Ok!");
}if (strReturnValue === SP.UI.DialogResult.cancel) // Perform action on Cancel.
{//alert("User clicked Cancel!");}
}
 
</script>

In the button click event call the below code  

var url = "http;//www.google.com";

ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "CustomScript", "OpenDialog('" + url + "', 994, 1000, 'Title', null);", true); 


We are using the code
ExecuteOrDelayUntilScriptLoaded(test, "sp.js")

because the sharepoint API for sharepooint modal pop up dialog window is present in  sp.js sometime this is loaded after the javscript function is called which will result in error.Hence inorder to get over it we force the loading of sp.js before the function is executed ...


Also add below links in page

<SharePoint:ScriptLink ID="ScriptLink1" Name="sp.ui.dialog.js" LoadAfterUI="true" Localizable="false" runat="server"></SharePoint:ScriptLink>
<%--<Sharepoint:ScriptLink ID="ScriptLink2" Name="SP.UI.Dialog.debug.js" LoadAfterUI="true" Localizable="false" runat="server"></Sharepoint:ScriptLink>--%>
<SharePoint:ScriptLink ID="ScriptLink3" Name="sp.js" LoadAfterUI="true" Localizable="false" runat="server"></SharePoint:ScriptLink>




To redirect to page or close popup on button click see the link Close popup

Error in content type deployment while visual studio deployment .Content type Id already exists for this feature ID

I encountered a starnge error.I just created a content type through Visual studio 2012 using some site columns deployed it ,it worked fine.But now I made some changes and try to redeploy it.It poped up with a errror stating "Content type with the ID ______ in the feature ID ________ already exists"


I tried retract and deploy again and again it dint work

The trick was .

1) Retract the solution
2)Close the Visual studio
3)Restart and redploy
4)It will work fine .

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