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.