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()

Creating Site Columns Programmatically through Elements.xml using all Datatypes

 <Field
       ID="{490f380c-ee51-41e1-8d7d-79aab5ca1d53}"
       Name="Clinic - Patient Name"
       DisplayName="Patient Name"
       Type="Text"
       Required="FALSE"
       Group="Clinic Site Columns">
  </Field>  <!--DataTypes = SingleLineText-->

  <Field
     ID="{FAD4C40B-A5B6-45A1-9C3D-D3494ABCA658}"
     Name="Clinic - Patient ID"
     DisplayName="Patient ID"
     Type="Number"
     Required="TRUE"
     Group="Clinic Site Columns">
  </Field>  <!--DataTypes = Integer-->

  <Field
     ID="{9A526521-3F1B-4AA9-B1E4-6F93C27A76F8}"
     Name="Clinic - Doctor Name"
     DisplayName="Doctor Name"
     Type="Text"
     Required="FALSE"
     Group="Clinic Site Columns">
  </Field>

  <Field
    ID="{02B25AC1-EBAA-464A-B543-829A033ADC58}"
    Name="Clinic - Doctor Address"
    DisplayName="Doctor Address"
    Type="Note"
    Required="FALSE"
    Group="Clinic Site Columns">
  </Field>      <!--DataTypes = Multiline-->

  <Field ID="{943E7530-5E2B-4C02-8259-CCD93A9ECB18}"
       Name="DoctorType"
       DisplayName="DoctorType"
       Type="Choice"
       Required="FALSE"
       Group="Clinic Site Columns" Format="Dropdown">
    <CHOICES>
      <CHOICE>Audiologists</CHOICE>
      <CHOICE>Allergist</CHOICE>
      <CHOICE>Andrologists</CHOICE>
      <CHOICE>Cardiologist</CHOICE>
      <CHOICE>Dentist</CHOICE>
      <CHOICE>Dermatologists</CHOICE>
    </CHOICES>
  </Field>     <!--ChoiceFormat = Dropdown-->

  <Field ID="{07BFA6D1-8730-4EAD-AEAD-428F0D924A12}"
       Name="DoctorTypeByRadioButton"
       DisplayName="DoctorTypeByRadioButton"
       Type="Choice"
       Required="FALSE"
       Group="Clinic Site Columns" Format="RadioButtons">
    <CHOICES>
      <CHOICE>Audiologists</CHOICE>
      <CHOICE>Allergist</CHOICE>
      <CHOICE>Andrologists</CHOICE>
      <CHOICE>Cardiologist</CHOICE>
      <CHOICE>Dentist</CHOICE>
      <CHOICE>Dermatologists</CHOICE>
    </CHOICES>
  </Field>
  <!--ChoiceFormat = RadioButton-->

  <Field ID="{1511BF28-A787-4061-B2E1-71F64CC93FD5}"
         Name="DateOpened"
         DisplayName="Date Opened"
         Type="DateTime"
         Format="DateOnly"
         Required="FALSE"
         Group="Clinic Site Columns">
    <Default>[today]</Default>
  </Field>    <!--DataTypes = DateTime-->

  <Field ID="{060E50AC-E9C1-4D3C-B1F9-DE0BCAC300F6}"
        Name="Amount"
        DisplayName="Amount"
        Type="Currency"
        Decimals="2"
        Min="0"
        Required="FALSE"
        Group="Clinic Site Columns" />

  <!--Rich Text HTML-->

  <Field ID="{13cd0291-df15-4278-9894-630913e4d2b9}"
   StaticName="AccrediterDescription"
   Name="AccrediterDescription"
   DisplayName="Accrediter_Description"
   Description="Accrediter Description of Item" Type="Note" NumLines="6" RichText="TRUE" RichTextMode="FullHtml" Group="Clinic Site Columns" />

  <!--HyperLink & Image-->
  <Field ID="{635a2031-2088-4413-b54e-d2af5daf08bf}"
   StaticName="ImageAuthor"
   Name="ImageAuthor"
   DisplayName="Image_Author"
   Description="Author Image" Type="URL" Format="Image" Group="Clinic Site Columns" />

  <!--YES/No Boolean-->
  <Field ID="{11018312-58f9-4eb0-867d-71298f82d98d}" Name="isActive" StaticName="isActive" DisplayName="isActive" Description="Select if Item is Active" Group="Clinic Site Columns" Type="Boolean">
    <Default>0</Default>
  </Field>