Friday, 21 September 2012

How to use Sharepoint2010 List Template




    You can create a list template and restore it in any places as a list.

CREATE A LIST TEMPLATE:


       Do it in following way.

(Open your site->)list->list settings->save list as a template

and save the template at any place you want.


RESTORE THE TEMPLATE TO LIST:


      Do it in following way

(open your site)->site actions->site settings->gallaris->list templates->(document->upload document)

     And after that

Site Actions->more Options->list->(there you can find your template name.And select that template name)

Sharepoint 2010 web or subsite Backup Restore



BACKUP AND RESTORE OF A WEB OR SUBSITE IN SHAREPOINT 2010


Backup web:


        Open sharepoint power shell. and type the following  command on your power shell

Import-spweb <fullurl which u want to backup> -path <location>  

Restore web:


        Open sharepoint power shell. and type the following  command on your power shell

Export-spweb <fullurl where u want to restore> -path <location>

Tuesday, 12 June 2012

How to populate people group field in sharepoint list -- server object model

                   
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.IO;

namespace peoplegroup
{

    public partial class peoplegroupUserControl : UserControl
    {

       protected void btnSubmit_Click(object sender, EventArgs e)
        {

             string owneraccounts = pplpicker.CommaSeparatedAccounts;

             char[] split = { ',' };
            SPSite site = SPContext.Current.Site;
            SPWeb web = site.RootWeb;
            SPList ownerList = web.Lists["ownerdetails"];
            SPListItem ownerListItem = ownerList.Items.Add();
            ownerListItem["owner"] = PersonIncharge();
           
            web.AllowUnsafeUpdates = false;
            ownerListItem.Update();
            web.AllowUnsafeUpdates = true;


                 }

}
}

Aspx  Code

<SharePoint:PeopleEditor ID="pplpicker" runat="server" Height="25px"
                Width="200px" AutoPostBack="True" BorderStyle="Groove" DialogHeight="200"
                DialogWidth="200" MultiSelect="False" Rows="1"
                SelectionSet="User,SecGroup,SPGroup" />


<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click"/>
             
             string[] splitPeoplePickerData = owneraccounts.Split(split);
            
             SPFieldUserValueCollection pplgrpcoll = new SPFieldUserValueCollection();

              for (int i = 0; i < splitPeoplePickerData.Length; i++)

            string[] splitPPData = Accounts.Split(splitter);
              {
                string SelectedAccount = splitPeoplePickerData[i];

                if (SelectedAccount != string.))
                 {
                  SPUser user = web.SiteUsers[SelAccount];

                  
                 SPFieldUserValue pplgrpfld = new SPFieldUserValue(web, user.ID, user.LoginName);

                    pplgrpcoll.Add(pplgrpfld);
                 }
               }

Wednesday, 16 May 2012

How to edit List Items in Sharepoint Silverlight Client Object Model


Here  consider  we have a list of Employee  Details ,first we will fetch the details
for a particular employee into text boxes then edit them and update them to the list


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;


namespace EmployeeDetailsEdit

{

public partial class MainPage : UserControl

{

ClientContext cc1;
ListItem litem;
List EmployeeDetails;
ListItemCollection _icoll;

string tmp, Title, EmployeeName, JoinDate,Address;
public MainPage() 
{


InitializeComponent();


cc1 = new ClientContext(ApplicationContext.Current.Url);
cc1.Load(cc1.Web);

EmployeeDetails = cc1.Web.Lists.GetByTitle("EmployeeDetails");

cc1.Load(EmployeeDetails );

CamlQuery qry = new Microsoft.SharePoint.Client.CamlQuery();
string q = "<view/>";
qry.ViewXml = q;

_icoll = auditp.GetItems(qry);

cc1.Load(_icoll);
cc1.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucess), null);


 }



private void SubmitButton_Click(object sender, RoutedEventArgs e)
{


litem = EmployeeDetails.GetItemById(ID);

litem["Title"] = textBox1.Text;
litem["Employee_x0020_Name"] = textBox2.Text;
litem["Join_x0020_Date"] = datePicker1.Text.ToString();

litem["Address"] = textBox3.Text;
litem.Update();


cc1.Load(EmployeeDetails, list => list.Title);

cc1.ExecuteQueryAsync(sucess, null);

}


private void sucess(Object sender, ClientRequestSucceededEventArgs args)

{
// This is not called on the UI thread.
Dispatcher.BeginInvoke(datafetch);

}

private void datafetch()
{


foreach (ListItem l in _icoll)
{


if (l["Employee_x0020_Name"].ToString() == "Joseph")
{
tmp = l["ID"].ToString();

Title= l["Title"].ToString();
EmployeeName= l["Employee_x0020_Name"].ToString();
JoinDate= l["Join_x0020_Date"].ToString();
Address= l["Address"].ToString();

}


}

ID = Convert.ToInt32(tmp);
textBox1.Text = Title;
textBox2.Text = EmployeeName;
datePicker1.Text = JoinDate;
textBox3.Text = Address;}

}

}
}

Tuesday, 24 April 2012

How to fetch sharepoint list data into a grid - Server Object Model




Here in this example in my sharepoint site i have created  a  list called "Employee Details"
with two columns "Name" and "EmpID".


Now in my sharepoint visual webpart project ,i have placed a datagrid and renamed it to  "grdDisplay".


Then i used the following in the code behind page to fetch data from the list into the datagrid.


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.IO;

namespace fetchlistdata
{
    public partial class fetchlistdataUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            gridData();
        }

        protected void gridData()
        {
            SPSite site = SPContext.Current.Site;
            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["Employee Details"];
            SPQuery query = new SPQuery();
           
            SPListItemCollection items = list.GetItems(query);

            DataTable tbl = new DataTable();
            tbl.Columns.Add("Name");
            tbl.Columns.Add("EmpID");

            DataRow tr;
            foreach (SPListItem item in items)
            {
                tr = tbl.Rows.Add();
                tr["Name"] = Convert.ToString(item["Name]);
                tr["EmpID"] = Convert.ToString(item["EmpID"]);

            }

            grdDisplay.DataSource = tbl;
            grdDisplay.DataBind();

                   
        }
}
}

Friday, 20 April 2012

How to restore a top level site to a subsite using sharepoint powershell

Restore toplevel site to subsite
--------------------------------------

first export  the top level site http://server1:1111/  using  sharepoint powershell


Export :       stsadm -o export -url <fullurl which u want to export> -filename <location:filename.dat>


Now create a subsite  in another sharepoint server


Import :         stsadm -o import -url <destination url> -filename <location where u stored.dat file>


 Replace  Destination  Url with subsite url   example -- http://server2:1234/subsite/