Code for creating list and column through Visual Studio(WIndows Form Application) for SharePoint 2010

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;


namespace Demo
{
    public partial class Form1 : Form
    {
        private const string siteurl = "http://win-5dlgan2f7s8:21905/CrimsonConsultingHR/Demo/";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (var site = new SPSite(siteurl))
            {
                var web = site.RootWeb;

                var ListId=web.Lists.Add("Authors", string.Empty, SPListTemplateType.GenericList);
                var List = web.Lists[ListId];
                List.OnQuickLaunch=true;

                List.ValidationFormula = "If([EmpId],TRUE,[Salary]<=50)";
                List.ValidationMessage = "The max salary for a Employee is $50";

            


                var title = List.Fields["Title"];
                title.Title = "Name";
                title.Update();


                var EmpId=List.Fields.Add("EmpId",SPFieldType.Boolean,false);
                var EmpSal=List.Fields.Add("Salary",SPFieldType.Currency,true);
                //var sal = List.Fields[EmpSal] as SPFieldCurrency;
                //sal.CurrencyLocaleId =
               

                var EmpDes=List.Fields.Add("Description",SPFieldType.Note,false);
                var Des=List.Fields[EmpDes] as SPFieldMultiLineText;
                Des.NumberOfLines=6;
                Des.RichText=false;
                Des.Update();

                var view = List.DefaultView;
                view.ViewFields.Add(EmpId);
                view.ViewFields.Add(EmpSal);
                view.ViewFields.Add(EmpDes);
                view.Update();

                List.Update();

                var item2=List.Items.Add();
                item2[title.Title]="Amit";
                item2[EmpId]=true;
                item2[EmpSal]=60;
                item2[EmpDes]="kuch kaam ka nae hai";
                item2.Update();
              


                var item1=List.Items.Add();
                item1[title.Title]="Gunjan";
                item1[EmpId]=false;
                item1[EmpSal]=15;
                item1[EmpDes]="Thik thak hai kaam kr leta hai kabhi kabhi";
                item1.Update();



                 var item=List.Items.Add();
                item[title.Title]="Himanshu";
                item[EmpId]=true;
                item[EmpSal]=58;
                item[EmpDes]="chor hai saala";
                item.Update();

               
                listBox1.Items.Add("Author list created");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (var site = new SPSite(siteurl))
            {
                var web = site.RootWeb;
                var list = web.Lists.TryGetList("Authors");

               
                if (list!= null)
                {
                    list.Delete();

                }
                listBox1.Items.Add("Author list deleted");

            }
        }
    }
}

Comments

Popular posts from this blog

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

How to import CSV files into DataTable in C#

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

go to top image