Friday, February 18, 2011

How To bind sharepoint List with Grid view in Webpart? Part 3 - adding Checkbox

Question : How To bind sharepoint List with Grid view in Webpart? Part 3 adding Checkbox

Solution :  adding checkbox for selection  for this we have to write a class first.
name of class : CheckBoxSupportClass.cs)using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
namespace WBP_TempWebPart
{
  public  class CheckBoxSupportClass:ITemplate
    {
        private ListItemType _itemType;
        private string _columnName;
        public CheckBoxSupportClass(ListItemType itemType, string columnName)
        {
            _itemType = itemType;
            _columnName = columnName;
        }
        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            switch (_itemType)
            {
                case ListItemType.Header:
                    LiteralControl header = new LiteralControl();
                    header.Text = string.Format("<b>{0}</b>", _columnName);
                    container.Controls.Add(header);
                    break;
                case ListItemType.Item:
                    CheckBox checkboxitem = new CheckBox();
                    checkboxitem.ID = "selectedTask";
                    checkboxitem.Visible = true;
                    container.Controls.Add(checkboxitem);
                    HtmlInputHidden taskIdItem = new HtmlInputHidden();
                    taskIdItem.ID = "taskIdItem";
                    container.Controls.Add(taskIdItem);
                    break;
                default:
                    break;
            }
        }
        #endregion
    }
}
--------------------------------
and then
-------------------------------
2) Now by adding reference of the above class we have to code the following
 private void BindGridWithList() {
           
SPGridView oGrid = new SPGridView();
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["Personnel"];
            SPQuery myquery = new SPQuery();
            myquery.Query = "<Where><Neq><FieldRef Name='EmployeeName' /><Value Type='Text'> </Value></Neq></Where><OrderBy><FieldRef Name='EmployeeName' Ascending='True' /></OrderBy>";
            SPListItemCollection myitemcol = list.GetItems(myquery);
           
            TemplateField selectTaskColumn = new TemplateField();
            selectTaskColumn.HeaderText = "Select Task";
            selectTaskColumn.ItemTemplate = new CheckBoxSupportClass(ListItemType.Item, "Select Task");
            oGrid.Columns.Add(selectTaskColumn);
                       
            DataTable table = new DataTable();
           
            //table.Columns.Add("Select");
            table.Columns.Add("Employee Name");
            table.Columns.Add("Employee Group");
            table.Columns.Add("Employee JobRole");
            table.Columns.Add("Status");
            table.Columns.Add("Last Taken");
            table.Columns.Add("Applied Assignment");
            string status = string.Empty;
            foreach (SPListItem item in myitemcol){
                DataRow row = table.NewRow();
                //row["Select"] = string.Empty;
                row["Employee Name"] = item["EmployeeName"].ToString();
                row["Employee Group"] = item["EmployeeGroup"].ToString();
               
                //row["Employee JobRole"] = item["EmployeeJobRole"].ToString();
                row["Employee JobRole"] = GetJobRole(item["EmployeeJobRole"].ToString());
               
                //to do call the function for find out the course status, last taken and applied assignment
                //FindCourseStatusFromAssignment(item["EmployeeName"].ToString(), "LastTaken", "AppliedAssignment");
                status = FindCourseStatusFromAssignment(item["EmployeeName"].ToString(), "LastTaken", "AppliedAssignment");
                //row["Status"] = status;
                row["Status"] = GetJobRole(status);
                table.Rows.Add(row);
            }
            DataView mydataview = new DataView(table);
            //table = mydataview.ToTable(true,"Select", "EmployeeName", "EmployeeGroup", "EmployeeJobRole", "Status");//, "Select Country", "Select State");
            table = mydataview.ToTable(true,  "Employee Name", "Employee Group", "Employee JobRole", "Status","Last Taken","Applied Assignment");//, "Select Country", "Select State");
            oGrid.DataSource = table;
            //oGrid.TemplateControl.Controls.Add(chkBox);
            oGrid.DataBind();
        }

How To bind sharepoint List with Grid view in Webpart- Part 2 Bind using List and Query on the list

Question : How To bind sharepoint List with Grid view in Webpart ? Part 2 Bind using List and Query on the listSolution :  for this we have add reference system.data.dll .  Bind using List and Query on the list

private void BindGridWithList() {
SPGridView oGrid = new SPGridView();
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["Personnel"];
            SPQuery myquery = new SPQuery();
            myquery.Query = "<Where><Neq><FieldRef Name='EmployeeName' /><Value Type='Text'> </Value></Neq></Where><OrderBy><FieldRef Name='EmployeeName' Ascending='True' /></OrderBy>";
            SPListItemCollection myitemcol = list.GetItems(myquery);
            DataTable table = new DataTable();
            table.Columns.Add("EmployeeName");
            foreach (SPListItem item in myitemcol){
                DataRow row = table.NewRow();
                row["EmployeeName"] = item["EmployeeName"].ToString();
  //next row(s) and add these rows
                table.Rows.Add(row);
            }
            DataView mydataview = new DataView(table);
            table = mydataview.ToTable(true, "EmployeeName");
            oGrid.DataSource = table;
            oGrid.DataBind();

        }

How To bind sharepoint List with Grid view in Webpart?

Question : How To bind sharepoint List with Grid view in Webpart?

Solution 1: Simple bind

private void BindGridWithList() {
            SPGridView oGrid = new SPGridView();
            SPWeb CurrentSite = SPContext.Current.Web;
            SPList PersonnelList = CurrentSite.Lists["Personnel"];
           
            BoundField colEmployeeName = new BoundField();
            BoundField colEmployeeGroup = new BoundField();
            BoundField colEmployeeJobRole = new BoundField();
                                 
            colEmployeeName.DataField = "EmployeeName";           
            colEmployeeName.HeaderText = "EmployeeName";
            colEmployeeGroup.DataField = "EmployeeGroup";
            colEmployeeGroup.HeaderText = "EmployeeGroup";
            colEmployeeJobRole.DataField = "EmployeeJobRole";
            colEmployeeJobRole.HeaderText = "EmployeeJobRole";           
            oGrid.Columns.Add(colEmployeeName);
            oGrid.Columns.Add(colEmployeeGroup);
            oGrid.Columns.Add(colEmployeeJobRole);
            SPDataSource PersonnelDataSource = new SPDataSource();
           
            PersonnelDataSource.List = PersonnelList;
            oGrid.AutoGenerateColumns = false;
            oGrid.DataSource = PersonnelDataSource;
            oGrid.DataBind();
        }

Friday, February 4, 2011

Insert Bulk data in Sharepoint

Question: How to insert the bulk data(near about 1000 and more records) in sharepoint list.?
Answer : I tried to insert the data in sharepoint list. And this data is near about 1000 records and above.
Here we go to insert using "XML BATCH PROCESS"
I belive me that this insertion takes only few seconds. yes only few seconds
here is the sample code.
try
      {
        StringBuilder methodBuilder = new StringBuilder();
        string batch = string.Empty;
        DateTime currentDate = DateTime.Now;
        string formattedDate = DateTime.Now.ToString();

        string methodFormat = string.Empty;

        SPSite site = new SPSite("http://localhost");

        SPWeb CurrentSite = SPContext.Current.Web ;         

            // Get the list containing the items to update.           
            SPList list = CurrentSite.Lists["TempList"];
            string listGuid = list.ID.ToString();
                                 
             for (int i = 0; i < 1000; i++)
             { 
               int itemID = i;
              
               string strPost = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<ows:Batch OnError=\"Return\">" +
                  "<Method ID=\"A1\"><SetList>" + listGuid + "</SetList>" +
                    "<SetVar Name=\"ID\">New</SetVar>" +
                    "<SetVar Name=\"Cmd\">Save</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#Title\">" + "New</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#EnrollmentType\">" + "Normal </SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#EmployeeName\">" + CurrentSite.CurrentUser.Name.ToString()+"</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#EmployeeNumber\">" + CurrentSite.CurrentUser.ID.ToString() +"</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#EmployeeAccount\">" + CurrentSite.CurrentUser.LoginName.ToString() + "</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#PhoneNo\">123456</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#AssignmentType\">Individual</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#Flag\">N</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#Status\">Assigned/RFE Not Sent</SetVar>" +
                    "<SetVar Name=" + "\"urn:schemas-microsoft-com:office:office#AssignmentID\">" + "ASN" + i + "</SetVar>" +
                  "</Method>"+"</ows:Batch>";
               string strProcessBatch = SPContext.Current.Web.ProcessBatchData(strPost);

             }
       
      } 
      catch (Exception ex) {
        inputName.Text = ex.Message;
      }

Site creation in other language using WSS 3.0 SP2

Using variation we are easily create the sites in other languages like French, German, ....
but this Variation is not available in WSS 3.0 SP1 and SP2 also.

Question: So is it possible to develop the sites in other languages?

Answer : Yes,we can develop the sites in other languages also in WSS 2.0 with SP2 as well as with the help of Sharepoint
language pack
for download the WSS3.0 SP2:
use : http://www.microsoft.com/downloads/en/details.aspx?FamilyID=79bada82-c13f-44c1-bdc1-d0447337051b&displaylang=en
and for language pack
use : http://www.microsoft.com/downloads/en/details.aspx?FamilyId=36EE1BF0-652C-4E38-B247-F29B3EEFA048&displaylang=en

just we follow the things.
1) use change language dropdown, select the language as you like and press change button
2) download the exe file.
3) save it and run it.
4) Reset the IIS

Now we have a choice to develop the sites in other language(French,German,...) also.
Now we are eaisly create the site in other language also.

Its very easy.

Shrikant Kinhikar

Wednesday, December 15, 2010

First Solution

Hi,

I am Shrikant Kinhikar, trying to provide first solution for your problems.

Let me start from myself. I face the problem in Sharepoint.

Problem: I Need to Start Workflow but error occur that "the form cannot be displayed because session state is not available. sharepoint workflow".

First Solution: open the web.config file for the site, search for the word "SessionStateModule" and uncomment that line.
i.e:  <!-- <add name="Session" type="System.Web.SessionState.SessionStateModule"/> -->
it should be:
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>>
--------------------------------------------------------------------------------------