Shalvin Interests

Monday, December 10, 2012

Drummer jokes


1. A guitarist asked a drummer why he prefers drum over guitar. The drummer answered atleast with drums you can loose cholesterol.

2. A guitarist wanted to torture the drummer, so he hid one of the drummer's sticks. After looking around, the drummer fell to his knees, raised his eyes to heaven, held up his remaining stick, and said, "Thank you Lord, for making me a conductor".


3. Two girls are walking down the road  when they hear, "Ssh! Down here". They looked down and see a frog, who says, "If you kiss me I'll turn into a famous drummer and make you rich and famous". One of the  girls reached down, grabs the frog, and stuffs it in her purse. The other girl says,  "Aren't you going to kiss him"? The first girl says, "No way! A talking frog is worth more than a famous drummer any day".


4. Why is a drum machine better than a drummer?
A. Because it keeps a steady beat and won't try to steal your girlfriend.


5. What's the difference between a drummer and government bonds?
Government bonds eventually mature and earn money.

6.What's the definition of a gentleman?
A. Someone who knows how to play the drums - but doesn't.

Sunday, October 14, 2012

Asp .Net GridView Events

The following events are triggered by GridView Control which can be used to customize the output:

DataBinding
RowCreated
RowDataBound
DataBound.

protected void GridView1_DataBinding(object sender, EventArgs e)
{
    Response.Write("1. Data Binding");
    Response.Write("<br/>");
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    Response.Write("2. Row created " + e.Row.Controls[0].ToString());
       
        Response.Write("<br/>");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    Response.Write("3. Row Data Bound");
        Response.Write("<br/>");
}
protected void GridView1_DataBound(object sender, EventArgs e)
{
    Response.Write("4. Data Bound");
}

Tuesday, August 28, 2012

SharePoint Client Object Model


SharePoint Client Object Model is a set of libraries and classes with which you can consume SharePoint data through a specific object model, which can be considered a subset of the SharePoint Object Model.

The client object model exposes a subset of the API that the server object model does, mainly focused on the Site-Collection level and lower.

The design of the client object model is to batch interaction with SharePoint to minimize the number of
round trips that it takes to interact with SharePoint services for common actions.


Multiple platform support :
  Managed Client
  Silverlight
  ECMA


The Client Object Model uses a client runtime proxy that communicates with a Windows Communication Foundation (WCF) service. The service is located at /_vti_bin/client.svc. 
To communicate, the client proxy sends batched XML commands and the WCF services respond with a result formatted using JavaScript Object Notation (JSON).
Because all commands are batched together and the JSON notation is a compact form, the Client Object Model bandwidth use is kept to a minimum.


Assembly Requirements

1.  Managed Client Object Model
  Microsoft.SharePoint.Client.dll
  Microsoft.SharePoint.Client.Runtime.dll
These files are located in the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI folder.


2.  Silverlight Client Object Model
Microsoft.SharePoint.Client.Silverlight.dll
Microsoft.SharePoint.Client.Silverlight.Runtime.dll
These files are located in \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\ClientBin

The reason for these .dlls being installed in a different location is due to how Silverlight works—
these .dlls are deployed to the same folder that some of the Silverlight building blocks are located in,
which makes it easier to access them from Silverlight.

3. ECMAScript Client Object Model
  A set of .js files
   SP.js
   SP.Core.js
   SP.Ribbon.js
   SP.Runtime.js

JavaScript files that are located in the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS folder

  These .js files are automatically downloaded to the browser when a use browses to SharePoint page.

There are also assemblies for working with REST/OData end points and Windows Phone.



Managed Client Object Model


using Microsoft.SharePoint.Client;

private void Form1_Load(object sender, 

EventArgs e)
{
    ClientContext ctx = new ClientContext

("http://shalvin");
    Site site = ctx.Site;
    ctx.Load(site);

    Web wb = site.RootWeb;

    ctx.Load(wb);

    ctx.ExecuteQuery();

    listBox1.Items.Add(ctx.Url);
    listBox1.Items.Add(site.Url);
}

Saturday, August 18, 2012

Replacing existing button with new Button in SharePoint 2010 with Custom Action

<CustomAction Id="Ribbon.Documents.New.NewFolder.ReplaceButton"
     Location="CommandUI.Ribbon"
     RegistrationId="101"
     RegistrationType="List"
     Title="Replace Ribbon Button">
    
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Documents.New.NewFolder">
          <Button Id="Ribbon.Documents.New.NewFolder.ReplacementButton"
            Command="MyNewButtonCommand"
            Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png?vk=4536" Image16by16Top="-240" Image16by16Left="-80"
            Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png?vk=4536" Image32by32Top="-352" Image32by32Left="-448"
            ToolTipTitle="Create a New Folder"
            ToolTipDescription="Replaced by XML Custom Action"
            LabelText="Shalvin New Folder"
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="MyNewButtonCommand"
          CommandAction="javascript:alert('New Folder Replaced by Shalvin');" />
      </CommandUIHandlers>
    </CommandUIExtension>
    
  </CustomAction>

Notification in SharePoint 2010

<CustomAction
  Id="NotificationDemo"
  RegistrationType="List"
  RegistrationId="101"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.New.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.NotificationDemo"
           Alt="Notification Button"
           Sequence="30"
           Image32by32="/_layouts/images/PPEOPLE.GIF"
           Command="NotificationDemo"
           LabelText="Notification Demo"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="NotificationDemo"
         CommandAction="javascript:SP.UI.Notify.addNotification('Hello from Shalvin', false);"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Friday, August 17, 2012

Dialog Framework With SharePoint 2010

 <CustomAction
  Id="DialogDemo"
  RegistrationType="List"
  RegistrationId="101"
  Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.New.Controls._children">
          <Button
           Id="Ribbon.Documents.New.Controls.Demo_Dialog"
           Alt="Dialog Ribbon Button"
           Sequence="30"
           Image32by32="/_layouts/images/PPEOPLE.GIF"
           Command="Demo_Dialog"
           LabelText="Dialog Demo"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
         Command="Demo_Dialog"
         CommandAction="javascript:
             var options = SP.UI.$create_DialogOptions();
             options.url = 'http://shalvin/Shalvin/Lists/Contacts/AllItems.aspx';
             options.width = 800;
             options.height = 600;
             SP.UI.ModalDialog.showModalDialog(options);"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

Adding Menu Item to General Settings in List Setting Section of SharePoint 2010

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Location ="Microsoft.SharePoint.ListEdit"
    GroupId="GeneralSettings"
    Title="ShalvinAction">
    <UrlAction Url="javascript:alert('Adding item to General Settings of List {SiteUrl}')"/>
  </CustomAction>
  
</Elements>


Custom Action for Adding a Menu to Site Actions in SharePoint 2010

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
   Location ="Microsoft.SharePoint.StandardMenu"
   GroupId ="SiteActions"
   Title ="ShalvinAction">
    <UrlAction Url="javascript:alert('Hello from Shalvin {SiteUrl}');" />
  </CustomAction>
 



Tuesday, January 24, 2012

Asp .Net ListView with Ado .Net Code

I am going to explore Asp .Net ListView with Ado .Net code. There are plenty of Asp .Net ListView articles out there explaining data binding with SqlDataSource. Unfortunately SqlDataSource can only  be used with toy projects.

<appSettings>
    <add key="ConnectionString" value="Data Source=.\sqlexpress;Initial Catalog=ContactManagement;Integrated Security=True"/>
  </appSettings>

I am using a table called ContactGroups with two fields GroupId and GroupName of which GroupId is an identity column.

I am creating its corresponding entity class called EContactGroups.

public class EContactGroups
{
    public int GroupId { get; set; }
    public string GroupName { get; set; }
}


In another class I am creating a method named GetGroups that will return an List of EContactGroups entity.
using System.Data.SqlClient;

public class BContactGroups
{
    SqlDataReader dr;
    SqlCommand cmd;
    DbConnect dbc = new DbConnect();
    public List<EContactGroups> GetGroups()
    {
        List<EContactGroups> glECG = new List<EContactGroups>();
        dbc.Open();
        cmd = new SqlCommand("select * from ContactGroups", dbc.cnn);
        dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            EContactGroups oECG = new EContactGroups();
            oECG.GroupId = Convert.ToInt32(dr["GroupId"]);
            oECG.GroupName = dr["GroupName"].ToString();

            glECG.Add(oECG);
        }
        dr.Close();
        return glECG;
    }
}


<asp:ListView ID="ListView1" runat="server">
    <LayoutTemplate>
        <table>
        <thead>
            <tr>
                
                <th>Group Id</th>
                <th>Group Name</th>
            </tr>                
        </thead>
        <tbody>
            <asp:Placeholder 
                id="itemPlaceholder" 
                runat="server" />
        </tbody>
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td><%# Eval("GroupId") %></td>
            <td><%# Eval("GroupName") %></td>
        </tr>
    </ItemTemplate>
    <EmptyDataTemplate>
        No records found
    </EmptyDataTemplate>
</asp:ListView>


public partial class _Default : System.Web.UI.Page
{
    BContactGroups objCG = new BContactGroups();
    protected void Page_Load(object sender, EventArgs e)
    {
        BindGroups();
    }

    private void BindGroups()
    {
        var g = (from p in objCG.GetGroups()
                 select p).ToList();

        ListView1.DataSource = g;
        DataBind();
    }
}