Posts

Showing posts from 2013

Code for adding Content Type through Visual Studio (Windows Form- 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 CreatecontentType_Click(object sender, EventArgs e)
        {
            using (var site = new SPSite(siteurl))
            {
                var web = site.RootWeb;

                var empFieldName = web.Fields.Add("Employee", SPFieldType.Boolean, true);
                var employee = web.Fields.GetFieldByInternalName(empFieldName);
                employee.Group = "AayushContentType";
                employee.Update();


                var rateFieldName = web.Fields.Add("Salary/Rate", SPFieldType.Currency, false);

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";




                …

Code for adding HTML controls in Visual Web Part (For SharePoint 2010)

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 System.Web.UI.HtmlControls;
using System.Drawing;


namespace Sun_SharePointProject2.Gunjan
{
    [ToolboxItemAttribute(false)]
    public class Gunjan : WebPart
    {
        //   public WebPart1()
        //   {
        //       AllowClose=false;
        //   }
/* Here i have taken 2 textbox and 2 label and 1 button for showing a table which will have 3 rows and 2 columns and will contain username and password button and textbox for each label and a button to submit */
        private TextBox tx;
        private TextBox t1;
        private Label l;
        private Label l1;
        private Button bt;
        HtmlTextWriter writer;
        TableCell tc;
        protected override void CreateChildControls()
        {
            tc = new TableCell();
            Controls.Add(tc);
      …

Code for sorting Grid View items on basis of Name or ID or any other column in Visual Studio WebPart( For SharePoint 2010)

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace TimerSharePoint.SortGridView
{

/* Class for get and set value of columns of a list in SharePoint. I have taken these 5 columns */
    class Data
    {
        public string Name { get; set; }
        public string Branch { get; set; }
        public string Roll_No { get; set; }
        public string Address { get; set; }
        public string Mobile_No { get; set; }
    }

    class Datarollasc : IComparer<Data>
    {

/* When your field is of string data type(I have used String above in Data class) */
        public int Compare(Data x, Data y)
        {
            return string.Compare(x.Roll_No, y.Roll_No);
        }
/* When your field is of Int data type(Although I haven't used String above in Data class but if u have int type then use this commented code) */
        //pub…

Code for Composite web part(A dropdown will have initial value of list and on selecting value will show List)

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;

namespace GriddView.CompositeWebPart
{
    [ToolboxItemAttribute(false)]
    public class CompositeWebPart : WebPart
    {
        private DropDownList listdropdown;
        private GridView Itemgridview;
        protected override void CreateChildControls()
        {
            listdropdown = new DropDownList();
            listdropdown.AutoPostBack = true;
            listdropdown.SelectedIndexChanged += new EventHandler(listdropdown_SelectedIndexChanged);
            Controls.Add(listdropdown);

            Controls.Add(new LiteralControl("<br/><br/>"));
            Itemgridview = new GridView();
            Controls.Add(Itemgridview);


        }
        protected void listdropdown_SelectedIndexChanged(object sender,EventArgs e)
        {
            var web = SPCon…

Building Simple Web Part(With HTML)

protected override void RenderContents(HtmlTextWriter writer)
// Add a webpart (Don't select Sandboxed or Visual WebPart)
//Override CreateChildControl method
        {
            writer.RenderBeginTag(HtmlTextWriterTag.H2);
            writer.Write("Hello, world");
            writer.RenderEndTag();
        }

Code for viewing only that data which is selected from DropDown in Visual WebPart(SharePoint)

//Create a class to get and set value

class Data
    {
        public string Name { get; set; }
        public string Branch { get; set; }
        public string Roll_No { get; set; }
        public string Address { get; set; }
        public string Mobile_No { get; set; }
    }
   //Code fro Page Load
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                try
                {
                    SPList info = SPContext.Current.Web.Lists["cust"];
                    List<Data> data = new List<Data>();
                    foreach (SPListItem item in info.Items)
                    {
                        Data d = new Data();
                        d.Roll_No = item["Roll_No."].ToString();
                        d.Name = item["Name"].ToString();
                        d.Mobile_No = item["Mobile_No."].ToString();
                        d.Address = item["Addr…

How to retreive value from a list and display it in a GridView in SharePoint Through Visual Studio

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace Sun_SharePointProject2.sunVisualWebPart1
{
    class Data
    {
        public string studentId { get; set;}
        public string name {get; set;}
        public string address {get; set;}
        public string section { get; set; }
    }
    public partial class sunVisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SPList info = SPContext.Current.Web.Lists["Student List"];
                List<Data> data = new List<Data>();
                foreach (SPListItem item in info.Items)
                {
                    Data d = new Data();
                    d.studentId = item["Student ID"].ToString();
d.name = item[&quo…

Code for adding registration form on SharePoint through Visual Sudio

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
WebParts;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace Sun_SharePointProject2.sunVisualWebPart1
{
    class Data
    {
        public string studentId { get; set;}
        public string name {get; set;}
        public string address {get; set;}
        public string section { get; set; }
    }
    public partial class sunVisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                SPList info = SPContext.Current.Web.Lists["Student List"];
                List<Data> data = new List<Data>();
                foreach (SPListItem item in info.Items)
                {
                    Data d = new Data();
                    d.studentId = item["Student ID"].ToString();
d.name = item["Name"].ToStri…

How to alter column definition in SQL

Alter table test add constraint pk  primary key clustered(USerId)

Delete multiple asp.net gridview rows with checkbox selection and with confirmation

Introduction:

In this article I will explain how to delete multiple rows in gridview with checkbox selection and with confirmation message using asp.net.

Description:

I have one gridvew that contains multiple rows with checkboxes now my requirement is to delete rows in gridview based on checkbox selection.

First design the table in database and give name UserInformation ColumnName DataType UserId Int(set identity property=true) UserName varchar(50) FirstName varchar(50) LastName varchar(50) Location varchar(50) After completion table creation enter some dummy and design your aspx page like this
<htmlxmlns="http://www.w3.org/1999/xhtml"> <headrunat="server"> <title>Delete Rows in Gridview with Checkbox</title> <styletype="text/css"> .Gridview { font-family:Verdana; font-size:10pt;
go to top image