Wednesday, 31 July 2013

delete site collection sharepoint 2010 using powershell

Script:-
     
     Remove-SPSite -Identity "http://Abcd:32033/sites/Test1" -GradualDelete

Note:-
   
    http://Abcd:32033/sites/Test1 = Site collection url

Create a site collection in SharePoint 2010 using powershell Script

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]


Script :-

$siteURL = "http://Abcd:32033/sites/Test1";

$owner = "Abcd\Administrator"

$secondOwner = "Abcd\Administrator"

$template = "STS#0"

$description = "This is a sample site that was built using PowerShell."

New-SPSite $siteURL -OwnerAlias $owner -SecondaryOwnerAlias $secondOwner -name “PowerShell for SharePoint” -Template $template -Description $description

Note:-

siteURL  = Enter your Site Collection url based on your Webapplication url.
Owner =  Enter Your owner of the particular site Collection
secondOwner = Enter the  second owner of the site collection
Template = Choose your Template

 For Example

STS#0 is for create  Team Site
STS#1  is for create  Blank Site

STS#0 Team Site WSS
STS#1 Blank Site WSS
STS#2 Document Workspace WSS
MPS#0 Basic Meeting Workspace WSS
MPS#1 Blank Meeting Workspace WSS
MPS#2 Decision Meeting Workspace WSS
MPS#3 Social Meeting Workspace WSS
MPS#4 Multipage Meeting Workspace WSS
CENTRALADMIN#0 Central Admin Site WSS
WIKI#0 Wiki Site WSS
BLOG#0 Blog WSS
BDR#0 Document Center MOSS
OFFILE#1 Records Center MOSS
OSRV#0 Shared Services Administration Site MOSS
SPS#0 SharePoint Portal Server Site MOSS
SPSPERS#0 SharePoint Portal Server Personal Space MOSS
SPSMSITE#0 Personalization Site MOSS
SPSMSITE#0 Contents area Template MOSS
SPSTOPIC#0 Topic area template MOSS

Remove SharePoint User Groups using PowerShell in SharePoint 2010

    The below script for Remove SharePoint User Group using PowerShell

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]

     
   Script:-

      $spWeb = Get-SPWeb "http://abcd:32033/sites/SampleSite/"
     $spGroups = $spWeb.SiteGroups
     $groups = ("TestGroup")
     ForEach($group in $groups) {
     $spGroups.Remove($group)
     }
     $spWeb.Dispose()


   Note:-

     http://abcd:32033/sites/SampleSite/ =Site collection url
     TestGroup =User Group Name
      
                

convert datatable to json using C#

public string ConvertDataTabletoJson()
    {
        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));
        //
        // Here we add five DataRows.
        //
        table.Rows.Add(25, "Indocin", "David", DateTime.Now);
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
        string[] jsonArray = new string[table.Columns.Count];
        string headString = string.Empty;

        for (int i = 0; i < table.Columns.Count; i++)
        {
            jsonArray[i] = table.Columns[i].Caption; // Array for all columns
            headString += "'" + jsonArray[i] + "' : '" + jsonArray[i] + i.ToString() + "%" + "',";
        }

        headString = headString.Substring(0, headString.Length - 1);
     
        StringBuilder sb = new StringBuilder();
        sb.Append("[");

        if (table.Rows.Count > 0)
        {
            for (int i = 0; i < table.Rows.Count; i++)
            {
                string tempString = headString;
                sb.Append("{");

                // To get each value from the datatable
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    tempString = tempString.Replace(table.Columns[j] + j.ToString() + "%", table.Rows[i][j].ToString());
                }

                sb.Append(tempString + "},");
            }
        }
        else
        {
            string tempString = headString;
            sb.Append("{");
            for (int j = 0; j < table.Columns.Count; j++)
            {
                tempString = tempString.Replace(table.Columns[j] + j.ToString() + "%", "-");
            }

            sb.Append(tempString + "},");
        }

        sb = new StringBuilder(sb.ToString().Substring(0, sb.ToString().Length - 1));
        sb.Append("]");
        return sb.ToString(); // json formated output
    }

Tuesday, 30 July 2013

Programmatically create a folder in a document library in SharePoint 2010


        SPSite oSpSite = new SPSite(SPContext.Current.Site.ID);
        SPWeb oSPWeb = oSpSite.OpenWeb();
        SPList list = oSPWeb.Lists.TryGetList("Shared Documents");//Document Library Name
        SPFolderCollection folderColl = list.RootFolder.SubFolders;
        SPFolder newFolder = folderColl.Add("Months");                 //FolderName

how to open web.config file in SharePoint 2010


     C:\inetpub\wwwroot\wss\VirtualDirectories\Port no\Web


Monday, 29 July 2013

add SharePoint DateTimeControl in SharePoint 2010

1.Open "Visual Studio 2010"
2.Create an  "Empty Sharepoint Project"
3.Add the Microsoft.sharepoint dll in your project
4.create one "visual webpart" and paste the below code in the Design code

Code:-

<%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls"
   Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<spuc:DateTimeControl runat="server" ID="DateTimePickerControl1" />


Change Central Administration port Number using PowerShell

     1.Click "Start" button
     2.Choose the "Microsoft SharePoint 2010 Products"
     3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]
 
           Script:-

                      Set-SPCentralAdministration -Port <portnumber>

           Example :-
   
                      Set-SPCentralAdministration -Port 9999

sharepoint 2010 list all site collections name using powershell

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]
    4.Create one folder in "C" Drive Named it data

Script:-

  Get-SPWebApplication http://SampleWeb:32033/ | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL | Export-CSV C:\data\IterateAllSitesSubsites.csv

Note :-
            http://SampleWeb:32033/ =Web application url
            C:\data = Export url

Copy and move SharePoint list from one site to another site using PowerShell

                    Copy and move bulk SharePoint site collection list or library from one site to another SharePoint Site using PowerShell Script

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]

     4.Create one folder in "C" Drive Named it Backup

Script:-


   #Enter your Source Site collection Url
   $sourceWebUrl = "---------"
    
   #this is the destination Site Collection, where the lists will be copied to
   $destWebUrl = "-----------"
    
   #Location to store the export file
   $path = "C:\Backup"
    
   #comma delimited list of List Names to copy
   $lists = @("------ ", "-------")
    
    
   #Loop through the lists, export the list from the source, and import the list into the destination
   foreach($list in $lists)
   {
       "Exporting " + $sourceWebUrl + "/lists/" + $list
    
           export-spweb $sourceWebUrl -ItemUrl ("lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
    
       "Exporting complete."
    
    
    
       "Importing " + $destWebUrl + "/lists/" + $list
    
           import-spweb $destWebUrl -IncludeUserSecurity -path ($path + $list + ".cmp") -nologfile
    
       "Importing Complete"
       "`r`n`r`n"

   }


Example:-

    
   #Enter your Source Site collection Url
   $sourceWebUrl = "http://Abcd:32033/sites/SampleSite/"
   
   #this is the destination Site Collection, where the lists will be copied to
   $destWebUrl = "http://Abcd:32033/sites/BiSam"
   
   #Location to store the export file
   $path = "C:\ Backup"
   
   #comma delimited list of List Names to copy
   $lists = @("TestList", "TestList1","SampleList")
   
   
   #Loop through the lists, export the list from the source, and import the list into the destination
   foreach($list in $lists)
   {
       "Exporting " + $sourceWebUrl + "/lists/" + $list
   
           export-spweb $sourceWebUrl -ItemUrl ("lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
   
       "Exporting complete."
   
   
   
       "Importing " + $destWebUrl + "/lists/" + $list
   
           import-spweb $destWebUrl -IncludeUserSecurity -path ($path + $list + ".cmp") -nologfile
   
       "Importing Complete"
       "`r`n`r`n"
   }
 Note :-

  http://Abcd:32033/sites/SampleSite/ =Source site collection Url
  http://Abcd:32033/sites/BiSam  = Destination site collection Url
  TestList,TestList1,SampleList  = List Name

Backup and Restore a site collection in SharePoint 2010 using PowerShell

    1.Click "Start" button
    2.Choose the "Microsoft SharePoint 2010 Products"
    3.Click the "SharePoint 2010 Management Shell" [ run as Administrator ]
    4.Create one folder in "D" Drive Named it BackupFile

BackUp Script :-

     Backup-SPSite -Identity http://Abcd-pc:12121/sites/Sample/ -Path "D:\BackupFile\files.bak"

Restore Script:-

Restore-SPSite -Identity http://sithikspSite-pc:2222/sites/spsite -Path "D:\BackupFile\files.bak" -force

     Here.,
            http://Abcd-pc:12121/sites/Sample/   = From Site Collection url
            http://sithikspSite-pc:2222/sites/spsite = To site Site Collection url
            D:\BackupFile\ =BackupFolder url
            files.bak = BackupfileName
               



Saturday, 27 July 2013

SPListItemCollection to DataTable using C#


 They code for converting the SPListItemCollection datas to datatable using c#

            SPWeb oWebsite = SPContext.Current.Web;
            SPList oList = oWebsite.Lists["CustomListName"];
            SPListItemCollection collListItems = oList.Items;
            DataTable dt=new DataTable();
            dt = collListItems.GetDataTable();

Customize Site Action menu in SharePoint 2010 using Custom Action

1.Create an Empty Sharepoint Empty Project
2.Add an Element file
3.Write the below Code inside the Elements Tag

 <CustomAction
     Id="MyCustomAction"
     Description="This is my custom action."
     Title="Open Application Page"
     GroupId="SiteActions"
     Location="Microsoft.SharePoint.StandardMenu"
     ImageUrl="/_layouts/Images/SPCustomAction/MyImage.bmp"
     Sequence="10">
    <UrlAction Url="SitePages/TestPage1.aspx"/>
  </CustomAction>

Deploy your solution you will see the custom Menu in site Action Menu

Customize Site Settings Pages in SharePoint 2010

1.Create an Empty SharePoint Project
2. Add an Empty Element
3. Paste the below code inside the  Elements tags

  <CustomActionGroup Id="MyCustomGroup" Title="My Custom Group" Description="This is my custom group" ImageUrl="_layouts/images/SiteSettings_SiteCollectionAdmin_48x48.png"
  Location="Microsoft.SharePoint.SiteSettings" RequiredAdmin="Delegated" Sequence="1" />
  <CustomAction Id="HomePage" Title="My Home Page Action" Description="This is a short description of my Home Page."
  Location="Microsoft.SharePoint.SiteSettings" GroupId="MyCustomGroup" Sequence="100" >
  <UrlAction Url="SitePages/HomePage.aspx" />
  </CustomAction>

Deploy Your solution you will see the My Custom Group in site setting pages.


Thursday, 25 July 2013

Create Welcome Page in SharePoint 2010 programmatically

Using C# :-

                      using (SPSite site = new SPSite(SPContext.Current.Site.ID))
            {
                using (SPWeb web = site.RootWeb)
                {
                    web.AllowUnsafeUpdates = true;
                    SPFolder rootFolder = web.RootFolder;
                    rootFolder.WelcomePage = "SitePages/pageName.aspx"
                    rootFolder.Update();
                }
            }

Using Power Shell :-

            $SiteUrl = "http://abcd-pc:12121/sites/Samples/"
            Site = Get-SPWeb -identity $SiteUrl
            $RootFolder = $Site.RootFolder;
            $RootFolder.WelcomePage = "SitePages/pageName.aspx";
            $RootFolder.Update();
            $Site.Dispose()

sharepoint 2010 welcome page missing

Solution:-
             1.click the "Site Actions"
             2.Then click the "Site Setting"
             3.under "Site Collection Administration" click the "Site Collections Features"
             4.Just Activate the "SharePoint Server Publishing Infrastructure"
             5. Under "Site Actions" click "Manage Site features"
             6.Activate "SharePoint Server Publishing" Features

the timer job for this operation has been created but it will fail because the


      Solution:-

               1.open the Run prompt (Windows-key + R)
               2.Type "Services.msc"
               3.Just Start the "Sharepoint 2010 Administration" Services
             

the operation that you are attempting to perform cannot be com



   Solution:-

         just Create one New Web application and Restore your site collection then it will work.

The Microsoft SharePoint Foundation Administration 2010 service is not started. Start the service and try again.

  Solution:-
               1.open the Run prompt (Windows-key + R)
               2.Type "Services.msc"
               3.Just Start the "Sharepoint 2010 Administration" Services
               

error occurred in deployment step add solution a feature with id

Solutions:-
                  1.Go to features
                  2.Remove the webpart from the features and again add the same webpart
                  3.Re-build the Project.

cannot connect to performancepoint services contact the administrator for details

      solutions:-
           
                1.open sharepoint Central Administration
                2.Click the "Application Management" in the Quick Launch bar
                3.under "Service Applications" click "configure Service application associations"
                4.Click  "Default" in the "Application Proxy Group"
                5.just check the Performance Point is selected or not [ if not select that one]
                6.click "ok"

Error occurred in deployment step 'add solution' access to the path is denied


Solution:-
                 
               just  Reset the IIS

the expected version of the product was not found on the system sharepoint 2010


Solution :-
           1.open power shell (Run as Administrator)
           2.Type the installation setup full path like
           C:\Users\SystemAccountName\Desktop\office2010-kb2687564-fullfile-x64-glb.exe PACKAGE.BYPASS.DETECTION.CHECK=1
           3.Execute it your problem will solve..
                         

Hide Top Level Menu and Ribbon Programmatically in SharePoint 2010

1.create one textfile and then save the below css code  inside the file and then save the file in document library

<style type="text/css">
  #s4-leftpanel-content
{
        display:none;
}
   #s4-ribbonrow
{
        display:none;
}
   #s4-titlerow
{
        display:none;
}
   #s4-workspace
  {
         overflow-y: hidden !important;
  }
</style> 

2.Go to Site Actions create one new page  

3. In Ribbon menu control click the "Text Layout" icon   and choose the "Two Column" and add a content editor web part

4.Once it's added, click the Edit web part and select the above share document in the content link

5.We will see the content editor in our page that's not required to view in page content. We will again edit the content editor web part and set the "Chrome Type" to "None".

6.click ok button we will see the changes

Programmatically set permission level in sharepoint 2010 using c#

        Namespace :-
                using Microsoft.SharePoint.Client;
        Source Code:-
                ClientContext objContext = new ClientContext("------"); //Site collection URL
                GroupCreationInformation objCreateInfo = new GroupCreationInformation();
                objCreateInfo.Title = TextBox2.Text;
                Group objGroup = objContext.Web.SiteGroups.Add(objCreateInfo);
                RoleDefinition objDefination = objContext.Web.RoleDefinitions.GetByName                                               ("Contribute"); //PermissionLevel
                RoleDefinitionBindingCollection objBindingColl = new                                                                                 RoleDefinitionBindingCollection(objContext);
                objBindingColl.Add(objDefination);
                objContext.Web.RoleAssignments.Add(objGroup, objBindingColl);
                objContext.ExecuteQuery();

Programmatically get all list name in sharepoint 2010 using c#

                          
   Namespace :-
           using Microsoft.SharePoint.Client;
  Code :-
          ClientContext objCtxt = new ClientContext("--------");  //SiteCollectionurl
          Web objweb = objCtxt.Web;
          objCtxt.Load(objweb.Lists, alllists => alllists.Include(list => list.Title, list => list.Id));
          objCtxt.ExecuteQuery();
          foreach (List list in objweb.Lists)
          {  string ListName=list.Title;
          }

Wednesday, 24 July 2013

Repeater control with paging in share point 2010 using c#

1.open visual studio 2010
2.Create one Visual Web part
3.paste the below code inside the visual Web part

Design Code :-

<div>
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
             <div class="Employee_Info">
              </div>
           <hr />
             <span class="FirstName">First Name : <%#Eval("FirstName") %></span>
            <br></br>
             <span class="LastName">Last Name : <%#Eval("LastName")%></span>
            <br></br>
             <span class="Age">Age : <%#Eval("Age")%></span>
            <br></br>
             <span class="Address">Address : <%#Eval("Address")%></span>
            <br></br>
             <span class="City">city : <%#Eval("City")%></span>
            <br></br>
             <span class="State">State : <%#Eval("state")%></span>
            <br></br>
             <span class="Country">Country : <%#Eval("Country")%></span>
            <br></br>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    <div style="overflow: hidden;">
        <asp:Repeater ID="rptPages" runat="server"
            onitemcommand="rptPages_ItemCommand1">
            <ItemTemplate>
                <asp:LinkButton ID="btnPage"
                 style="padding:1px 3px; margin:1px; background:#ccc; border:solid 1px #666; font:8pt tahoma;"
                 CommandName="Page" CommandArgument="<%# Container.DataItem %>"
                 runat="server"><%# Container.DataItem %>
                </asp:LinkButton>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</div>
<table>
<tr>
<td class="style1">
<asp:LinkButton ID="lnkBtnPrev" runat="server" onclick="lnkBtnPrev_Click" >Previous</asp:LinkButton>
</td>
<td class="style2">
</td>
<td class="style2">
<asp:LinkButton ID="lnkBtnNext" runat="server" onclick="lnkBtnNext_Click" >Next</asp:LinkButton>
</td>
</tr>
</table>

Cs Code :-
 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        private void LoadData()
        {
            SPSite site = new SPSite("-------"); //Site Collection Url
            SPWeb web = site.OpenWeb();
            SPList listofEmp = web.Lists["Employee"];  //ListName
            SPListItemCollection col = listofEmp.GetItems();
            DataTable dtEmp = col.GetDataTable();
            int dtcount = dtEmp.Rows.Count;
            PagedDataSource pgitems = new PagedDataSource();
            System.Data.DataView dv = new System.Data.DataView(dtEmp);
            pgitems.DataSource = dv;
            pgitems.AllowPaging = true;
            pgitems.PageSize = 1;
            pgitems.CurrentPageIndex = PageNumber;
            if (pgitems.PageCount > 1)
            {
                rptPages.Visible = true;
                System.Collections.ArrayList pages = new System.Collections.ArrayList();
                for (int i = 0; i < pgitems.PageCount; i++)
                    pages.Add((i + 1).ToString());
                rptPages.DataSource = pages;
                rptPages.DataBind();
                if (dtcount - 1 == PageNumber)
                {
                    lnkBtnNext.Visible = false;
                }
                else
                {
                    lnkBtnNext.Visible = true;
                }
                if (PageNumber == 0)
                {
                    lnkBtnPrev.Visible = false;
                }
                else
                {
                    lnkBtnPrev.Visible = true;
                }
            }
            else
                rptPages.Visible = false;
            Repeater1.DataSource = pgitems;
            Repeater1.DataBind();

        }
        public int PageNumber
        {
            get
            {
                if (ViewState["PageNumber"] != null)
                    return Convert.ToInt32(ViewState["PageNumber"]);
                else
                    return 0;
            }
            set
            {
                ViewState["PageNumber"] = value;
            }
        }
    protected void rptPages_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            PageNumber = Convert.ToInt32(e.CommandArgument) - 1;
            LoadData();
        }

        protected void lnkBtnNext_Click(object sender, EventArgs e)
        {
            PageNumber++;
            LoadData();

        }

        protected void lnkBtnPrev_Click(object sender, EventArgs e)
        {
            PageNumber--;
            LoadData();
        }