Monday, 30 September 2013

Programmatically get all listName in share point using C#

                  String SiteURL = "";
                  SPSite site = new SPSite(SiteURL);
                  SPWeb myWeb = site.OpenWeb();
                  foreach (SPList aList in myWeb.Lists)
                  {
                      string ListTitle = aList.Title;
                      //string rootName = aList.RootFolder.Name;
                  }

Programmatically get all site collection Name in share point using C#

           SPWebApplication webApp = SPWebApplication.Lookup(new Uri(WebApp));
            foreach (SPSite site in webApp.Sites)
            {
                SPWeb thisweb = site.OpenWeb();
                string WebName = site.Url;
                string templateName = thisweb.WebTemplate;
                site.Dispose();
            }

Programmatically get all web application Name in share point using C#

            get all webapplicationName      
            string strurls = "";
            SPWebApplicationCollection webapps = SPWebService.ContentService.WebApplications;
            foreach (SPWebApplication webapp in webapps)
            {
                string WebName = webapp.DisplayName;
                foreach (SPAlternateUrl url in webapp.AlternateUrls)
                {
                  strurls = url.Uri + "";
                }
             }

Friday, 27 September 2013

Download wsp file using powershell in sharepoint

$farm = Get-SPFarm
$file = $farm.Solutions.Item("collegeprojectvisualwebpart1.wsp").SolutionFile
$file.SaveAs("c:\collegeprojectvisualwebpart1.wsp")

Add deploy wsp sharepoint


Add Wsp to CentralAdmin
Add-SPSolution -LiteralPath "C:\Users\Administrator\Desktop\My Collection\Example.wsp"

Deploy to all Web application:-
Install-SPSolution –Identity “Example.wsp”  –AllWebApplications –GACDeployment

Retract all Webapplication:-
Uninstall-SPSolution –Identity Example.wsp –AllWebApplications

Remove wsp:-
Remove-SPSolution –Identity Example.wsp

Datatable Example in c#

            DataTable table = new DataTable();
            table.Columns.Add("EmpID", typeof(int));
            table.Columns.Add("EmpName", typeof(string));
            table.Columns.Add("EmpAge", typeof(int));
            table.Columns.Add("DOB", typeof(DateTime));

            //auto increment column
            DataColumn column = new DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.AutoIncrement = true;
            column.AutoIncrementSeed = 1;
            column.AutoIncrementStep = 1;
            table.Columns.Add(column);

            //Add Values to DataTables
            table.Rows.Add(1, "Mohamed", 27, new DateTime (1986,05,06));
            table.Rows.Add(2, "sithik", 26,new DateTime (1986,08,11));
            table.Rows.Add(10, "Raja", 25,new DateTime(1985,12,05));
            table.Rows.Add(11, "uthaya",30,new DateTime(1983,10,10));
            table.Rows.Add(12, "Ela", 28,new DateTime (1985,12,23));

            DataView view = new DataView(table);
            DataRow[] result = table.Select("EmpAge >= 20 AND EmpName = 'sithik'");
            DataTable dt1 = result.CopyToDataTable();

             DataView view = new DataView(table);
            view.RowFilter = "DOB > #1/1/1986#";
            view.Sort = "EmpAge Desc";

Get all list Name in SharePoint using Powershell


Get-SPWeb http://sfs01:1111/sites/Demo1/ |
Select -ExpandProperty Lists |
Select Title

Get System Domain Name using powershell

Get-WmiObject Win32_ComputerSystem

Thursday, 26 September 2013

update Site Column using Power shell in sharepoint

$site = Get-SPSite -Identity "http://abcd:1111/sites/Demo1/"
$web = $site.RootWeb
$field=$web.Fields["EmpName"]
$field.Type= "Choice"
$field.Update($true)
$web.Dispose()
$site.Dispose()

create Site Column Using Power shell in sharepoint

$site = Get-SPSite -Identity "http://abcd:1111/sites/Demo1/"
$web = $site.RootWeb
$fieldXML = '<Field Type="Text"
Name="EmpName"
Description="Employee Name Column Info."
DisplayName="EmpName"
Group="Clinic Site Columns"
Hidden="FALSE"
Required="FALSE"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInListSettings="TRUE"
ShowInNewForm="TRUE"></Field>'
$web.Fields.AddFieldAsXml($fieldXML)
$web.Dispose()
$site.Dispose()