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