Wednesday 31 October 2012

sharepoint add lookup field programmatically-client object model

ADD LOOKUP FIELD PROGRAMMATICALLY SHAREPOINT 2010-CLIENT OBJECT MODEL


Insert the following namespace

using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

Use the following code.

ClientContext ccsite;
   List listobj;
   List listobj_lookup;            //Object for lookup list
   ListItemCollection _icoll; 
  public MainPage()
      {
           InitializeComponent();

           ccsite = new ClientContext(ApplicationContext.Current.Url);
           ccsite.Load(ccsite.Web);
           listobj = ccsite.Web.Lists.GetByTitle("ListName");
           listobj_lookup= ccsite.Web.Lists.GetByTitle("ListName");     // (LookUp List)
           ccsite.Load(listobj);
         
            CamlQuery qry = new CamlQuery();
            qry.ViewXml = "";

            _icoll_lookup= listobj_lookup.GetItems(qry);
            ccsite.Load(_icoll_lookup);          
            ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(success), null);
       }

 private void success(object sender,ClientRequestSucceededEventArgs arg)
    {
         Dispatcher.BeginInvoke(datacon);
     }

private void datacon()
   {
            //Geting List Item Record ID of lookup value
            int recordID = 0;
            foreach (ListItem item in _icoll_lookup)
            {
                if (Convert.ToString(item["ListItmeValue"]) == "YourString")
                { recordID = Convert.ToInt32(item["ID"]); }
            }

            //For insert Lookup value
            ListItem litem = listobj.AddItem(new ListItemCreationInformation());
            FieldLookupValue lookupobj = new FieldLookupValue { LookupId = recordID };
            litem["ColumnName1"] = lookupobj as FieldLookupValue;
            litem.Update();
            ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(succed), null);
    }

private void succed(object sender, ClientRequestSucceededEventArgs arg)
    { }
</ div>

ADD MULTIPLE LOOKUP FIELD PROGRAMMATICALLY SHAREPOINT 2010-CLIENT OBJECT MODEL

Insert the following namespace

using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
ClientContext ccsite;
   List listobj;
   List listobj_lookup;            //Object for lookup list
   ListItemCollection _icoll; 
  public MainPage()
      {
           InitializeComponent();

           ccsite = new ClientContext(ApplicationContext.Current.Url);
           ccsite.Load(ccsite.Web);
           listobj = ccsite.Web.Lists.GetByTitle("ListName");
           listobj_lookup= ccsite.Web.Lists.GetByTitle("ListName");     // (LookUp List)
           ccsite.Load(listobj);
         
            CamlQuery qry = new CamlQuery();
            qry.ViewXml = "<View/>";

            _icoll_lookup= listobj_lookup.GetItems(qry);
            ccsite.Load(_icoll_lookup);          
            ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(success), null);
       }

 private void success(object sender,ClientRequestSucceededEventArgs arg)
    {
         Dispatcher.BeginInvoke(datacon);
     }

private void datacon()
   {
            //Geting Multiple List Item Record ID of lookup value
             int[] recordID=new int[_icoll_lookup.Count];
             int count=0;
            foreach (ListItem item in _icoll_lookup)
            {
                if (Convert.ToString(item["ListItmeValue"]) == "YourString")
                   {
                    recordID[count] = Convert.ToInt32(item["ID"]);
                    count++; 
                     }
            }

            //For insert Multiple Lookup value
           ListItem litem = listobj.AddItem(new ListItemCreationInformation());
           FieldLookupValue[] lookupobj = new FieldLookupValue[count];
            for (int i = 0; i < count; i++)
            {
                lookupobj[i] = new FieldLookupValue{ LookupId = recordID[i] };
            }
            litem["ColumnName"] = lookupobj as FieldLookupValue[];
            litem.Update();
            ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(succed), null);
    }

private void succed(object sender, ClientRequestSucceededEventArgs arg)
  {
   } 

Tuesday 30 October 2012

Asp.net Static Charts




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data;

namespace StaticChart
{
    public partial class _Default : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            Chart1.DataSource = GetchartData();
            Chart1.DataBind();

        }

        public  DataTable GetchartData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Month", typeof(string));
            dt.Columns.Add("Date", typeof(DateTime));
            dt.Columns.Add("Sales1", typeof(int));
            dt.Columns.Add("Sales2", typeof(int));
            dt.Columns.Add("Sales3", typeof(int));

            DataRow row = dt.NewRow();
            row["Date"] = new DateTime(2006, 1, 1);
            row["Month"] = "January";
            row["Sales1"] = 100;
            row["Sales2"] = 100;
            row["Sales3"] = 200;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 2, 1);
            row["Month"] = "February";
            row["Sales1"] = 200;
            row["Sales2"] = 110;
            row["Sales3"] = 170;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 3, 1);
            row["Month"] = "March";
            row["Sales1"] = 300;
            row["Sales2"] = 140;
            row["Sales3"] = 290;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 4, 1);
            row["Month"] = "April";
            row["Sales1"] = 100;
            row["Sales2"] = 60;
            row["Sales3"] = 100;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 5, 1);
            row["Month"] = "May";
            row["Sales1"] = 300;
            row["Sales2"] = 160;
            row["Sales3"] = 120;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 6, 1);
            row["Month"] = "June";
            row["Sales1"] = 200;
            row["Sales2"] = 120;
            row["Sales3"] = 190;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 7, 1);
            row["Month"] = "June";
            row["Sales1"] = 200;
            row["Sales2"] = 160;
            row["Sales3"] = 220;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 8, 1);
            row["Month"] = "August";
            row["Sales1"] = 220;
            row["Sales2"] = 80;
            row["Sales3"] = 120;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 9, 1);
            row["Month"] = "September";
            row["Sales1"] = 270;
            row["Sales2"] = 200;
            row["Sales3"] = 100;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 10, 1);
            row["Month"] = "October";
            row["Sales1"] = 300;
            row["Sales2"] = 230;
            row["Sales3"] = 190;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 11, 1);
            row["Month"] = "November";
            row["Sales1"] = 260;
            row["Sales2"] = 100;
            row["Sales3"] = 200;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 12, 1);
            row["Month"] = "December";
            row["Sales1"] = 320;
            row["Sales2"] = 190;
            row["Sales3"] = 270;
            dt.Rows.Add(row);

            return dt;

        }
    }
}
   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="StaticChart._Default" %>

<%@ Register assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="height: 328px">
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" Height="391px">
              <asp:Chart ID="Chart1" runat="server" Height="371px" Width="642px">
                <series>
                    <asp:Series Name="Series1" XValueMember="Month" 
                        YValueMembers="Sales1">
                    </asp:Series>
                    <asp:Series Name="Series2" XValueMember="Month" 
                        YValueMembers="Sales2">
                    </asp:Series>
                    <asp:Series Name="Series3" XValueMember="Month" 
                         YValueMembers="Sales3">
                    </asp:Series>
                </series>
                <chartareas>
                    <asp:ChartArea Name="ChartArea1">
                    </asp:ChartArea>
                </chartareas>
            </asp:Chart>
        </asp:Panel>
    </div>
    </form>
</body>
</html>


Asp.net Dynamic Charts


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Data;

namespace DynamicChart
{
    public partial class _Default : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            Chart ch = new Chart();
            ChartArea ca = new ChartArea();
            ch.ChartAreas.Add(ca);
            ch.Width = 400;
            ch.Height = 500;
           
            ch.BackColor = System.Drawing.Color.AliceBlue;
            ch.DataBind();
            Series s1 = new Series();
            s1.Color = System.Drawing.Color.Blue;
            s1.ChartType = SeriesChartType.Bar;
            s1.XValueMember = "Month";
            s1.YValueMembers = "Sales1";

            Series s2 = new Series();
            s2.Color = System.Drawing.Color.Red;
            s2.ChartType = SeriesChartType.Bar;
            s2.XValueMember = "Month";
            s2.YValueMembers = "Sales2";

            Series s3 = new Series();
            s3.Color = System.Drawing.Color.Green;
            s3.ChartType = SeriesChartType.Bar;
            s3.XValueMember = "Month";
            s3.YValueMembers = "Sales3";

            ch.Series.Add(s1);
            ch.Series.Add(s2);
            ch.Series.Add(s3);
            ch.DataSource = GetchartData();
            ch.DataBind();
            Panel1.Controls.Add(ch);

        }

        public  DataTable GetchartData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Month", typeof(string));
            dt.Columns.Add("Date", typeof(DateTime));
            dt.Columns.Add("Sales1", typeof(int));
            dt.Columns.Add("Sales2", typeof(int));
            dt.Columns.Add("Sales3", typeof(int));

            DataRow row = dt.NewRow();
            row["Date"] = new DateTime(2006, 1, 1);
            row["Month"] = "January";
            row["Sales1"] = 100;
            row["Sales2"] = 100;
            row["Sales3"] = 200;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 2, 1);
            row["Month"] = "February";
            row["Sales1"] = 200;
            row["Sales2"] = 110;
            row["Sales3"] = 170;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 3, 1);
            row["Month"] = "March";
            row["Sales1"] = 300;
            row["Sales2"] = 140;
            row["Sales3"] = 290;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 4, 1);
            row["Month"] = "April";
            row["Sales1"] = 100;
            row["Sales2"] = 60;
            row["Sales3"] = 100;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 5, 1);
            row["Month"] = "May";
            row["Sales1"] = 300;
            row["Sales2"] = 160;
            row["Sales3"] = 120;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 6, 1);
            row["Month"] = "June";
            row["Sales1"] = 200;
            row["Sales2"] = 120;
            row["Sales3"] = 190;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 7, 1);
            row["Month"] = "June";
            row["Sales1"] = 200;
            row["Sales2"] = 160;
            row["Sales3"] = 220;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 8, 1);
            row["Month"] = "August";
            row["Sales1"] = 220;
            row["Sales2"] = 80;
            row["Sales3"] = 120;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 9, 1);
            row["Month"] = "September";
            row["Sales1"] = 270;
            row["Sales2"] = 200;
            row["Sales3"] = 100;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 10, 1);
            row["Month"] = "October";
            row["Sales1"] = 300;
            row["Sales2"] = 230;
            row["Sales3"] = 190;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 11, 1);
            row["Month"] = "November";
            row["Sales1"] = 260;
            row["Sales2"] = 100;
            row["Sales3"] = 200;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["Date"] = new DateTime(2006, 12, 1);
            row["Month"] = "December";
            row["Sales1"] = 320;
            row["Sales2"] = 190;
            row["Sales3"] = 270;
            dt.Rows.Add(row);

            return dt;

        }
    }
}
   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DynamicChart._Default" %>

<%@ Register assembly="System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body style="height: 328px">
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server" Height="391px">
        </asp:Panel>
    </div>
    </form>
</body>
</html>


CSS Menu





<html>
<head>
<title>CSS Menu</title>
<style >
        #navigation li ul
        {
             list-style: none;
             margin: 0;
             padding: 0;    
             visibility:hidden;
             position: absolute;
             z-index: 99999;
             visibility:hidden;
        }
        ul#navigation li:hover > ul
        {
             visibility:visible;
        }
        
       ul#navigation 
       {
            float:left;
            border-right:1px solid #c4dbe7;
       }

        ul#navigation li ul li a
       {
         width:100px;
         height:10px;
         font-size:8px;
         border-right:1px solid #C2C2C2;
        
       background-image: linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -o-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -moz-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -webkit-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -ms-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);

background-image: -webkit-gradient(
 linear,
 left bottom,
 left top,
 color-stop(0.23, rgb(32,217,217)),
 color-stop(0.62, rgb(59,255,245))
);

     }
    

     ul#navigation li a 
     {
     padding:10px 25px;
     color:#616161;
     display:inline-block;
     text-decoration:none;
     border-right:1px solid #fff;
     border-left:1px solid #C2C2C2;
     border-top:1px solid #fff;

background-image: linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -o-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -moz-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -webkit-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);
background-image: -ms-linear-gradient(bottom, rgb(32,217,217) 23%, rgb(59,255,245) 62%);

background-image: -webkit-gradient(
 linear,
 left bottom,
 left top,
 color-stop(0.23, rgb(32,217,217)),
 color-stop(0.62, rgb(59,255,245))
);
   
}

     ul#navigation ul 
      {
          top: 45px;
          left: 1px;
          width:100px;
       }

      ul#navigation li a:hover 
       {
           background-image: linear-gradient(bottom, rgb(135,245,245) 23%, rgb(185,250,246) 62%);
           background-image: -o-linear-gradient(bottom, rgb(135,245,245) 23%, rgb(185,250,246) 62%);
           background-image: -moz-linear-gradient(bottom, rgb(135,245,245) 23%, rgb(185,250,246) 62%);
           background-image: -webkit-linear-gradient(bottom, rgb(135,245,245) 23%, rgb(185,250,246) 62%);
           background-image: -ms-linear-gradient(bottom, rgb(135,245,245) 23%, rgb(185,250,246) 62%);

           background-image: -webkit-gradient(
                              linear,
                              left bottom,
                              left top,
                              color-stop(0.23, rgb(135,245,245)),
                              color-stop(0.62, rgb(185,250,246))
                              );
             color:#282828;
   
          }

       ul#navigation  li 
          {
           display:inline;
           font-size:12px;
           font-weight:bold;
           margin:0;
           padding:0;
           float:left;
           position:relative;
           border-top:1px solid #c4dbe7;
           border-bottom:2px solid #c4dbe7;
           }
    </style>
 </head>
 <body>
 <ul id="navigation">
        <li><a href="http://www.dotnetstadium.com">DotnetStadium</a></li>
        <li><a href="#">Services</a>
        <ul>
           <li><a href="#">WebSite Development</a></li>
           <li><a href="#">N/W Management</a></li>
           <li><a href="#">Software Management</a></li>
           <li><a href="#">Product Consultation</a></li>
        </ul>    
        </li>
         <li><a href="www.dotnetstadium.com">Downloads</a>
         <ul>
         <li><a href="#">softwares</a></li>
         <li><a href="#">games</a></li>
         <li><a href="#">themes</a></li>
         </ul>
         </li>
    </ul>
 </body>
 </html>