July 23, 2013

How to Add button in sharepoint 'Add New Item' / ‘Add new Announcment’ / ‘Add Document’ / 'Add New Discussion' list libraries on Top of defailt view / Top



I have goggled about this, found so many blogs but nothing worked as I was expecting, finally found my own successful way to 'Add New Item' / ‘Add new Announcement’ / ‘Add Document’ / 'Add New Discussion' to all list and libraries in SharePoint on Top of page. 


 var addButton = $(this).find("td.ms-addnew").html();  
 if(addButton != null)  
 {   
  $("div#WebPartWPQ2 td:first").prepend("<div style='margin-top: 12px;'>&nbsp;&nbsp;&nbsp;"+addButton+"<br/><br/></div><div class='ms-partline' ColSpan='2'></div>");   
 }   


for detailed code and step by step screenshots documents can be found here


------------------------------------------

and if you want To Hide Add New Item link button in sharepoint 2010 list of library
below information source : Raviraj
On home page add lists/libraries that you want and then select edit webpart and set toolbar 

type to "No Toolbar".
Or you can add style:

.ms-addnew{
 display:none;
}


on home page.
Make sure that ribbon is hidden
or try this on home page.

.ms-cui-row-onerow{
 display:none;
}




--
Regards,
Praveen Pandit

July 22, 2013

PowerShell how to add New Filed / Column type number / integer choice / DropDown in SharePoint

"PowerShell  how to add New Filed / Column type number / integer choice / DropDown in SharePoint"

Here is another example for How PowerShell is Powerful I mean useful.

Export List of site/ subsites

 $site = Get-SPSite "http://ServerName/SiteCollection"  
 Set-content ".\urls.csv" "URL"  
  foreach ($web in $site.AllWebs) {  
     write-host "Web URL -->" $web.URL  
     AC ".\urls.csv" $web.URL  
   }   

#above code will a CSV with heading URL and list of sites (like below) with name 'urls.csv'
URL
http://servername/B
http://servername/A

///////////////////////////// Add Number or Integer Column ////////////////////////////

  $csv = Import-CSV ".\urls.csv"  
  $spFieldType = [Microsoft.SharePoint.SPFieldType]::Number  
  $spFieldName = "Worked Hours"     
 foreach ($siteURL in $csv) {  
   # Web URL  
   $web = Get-SPWeb -Identity $siteURL.url;  
   # SPList name  
    $list = $web.Lists["Tasks"]  
   if($list -ne $null)  
   {  
     write-host "`nList is" $list "on Site " $web.Title " " $web.url;  
     $YN= Read-host "Press Enter to Confirm or Press ctrl+c"  
     if($YN -eq $null)  
     {  
      write-host "Checking Existing Columns."  
     $TF=$true;  
     ForEach ($id in $fld)  
     {  
       if($id -match $spFieldName)  
       {  
         Write-host "Column already exist`n" -foregroundcolor yellow;  
         $TF=$false;  
       }        
     }  
       if($TF)  
       {  
      Write-host "......Creating Column.....";      
      #The new field is not required Filed, so the value of the third parameter is 0  
      $list.Fields.Add($spFieldName, $spFieldType, 0)  
      $list.Update()  
      Write-host "Adding Decimal two places formate"  
      $spField = $list.Fields.GetField($spFieldName)  
      $spField.DisplayFormat = "2"    
      $spField.Update()  
      Write-host " **Item Added** `n" -foregroundcolor green  
      }  
      }  
   }  
   else{Write-Host "No List Found"}  
 }  

/////////////////////////////////// Add DropDown or Choice Column ////////////////////////////////////

  $spFieldName = "My Column"  
 $Choices = New-Object System.Collections.Specialized.StringCollection  
 $Choices.Add("Fixed")  
 $Choices.Add("Not Fixed")  
 $csv = Import-CSV ".\urls.csv"  
 foreach ($siteURL in $csv) {  
   # Web URL  
   $web = Get-SPWeb -Identity $siteURL.url;  
   # SPList name  
    $list = $web.Lists["Projects"]  
   if($list -ne $null)  
   {  
     write-host "`nList is" $list "on Site " $web.Title " " $web.url;  
     $YN= Read-host "To Confirm Press Enter......."  
     if($YN -eq '')  
     {  
     #column of type 'Choice Column'  
     $fld  = $list.Fields  
     write-host "Checking Existing Columns."  
     $TF=$true;  
     ForEach ($id in $fld)  
     {  
       if($id -match $spFieldName)  
       {  
         Write-host "Column already exist`n" -foregroundcolor yellow;  
         $TF=$false;  
       }        
     }  
       if($TF)  
       {  
         Write-host "......Creating Column.....";  
         #Add Choice Field to list  
         $list.Fields.Add($spFieldName,[Microsoft.SharePoint.SPFieldType]::Choice,$FALSE,$FALSE,$Choices)  
          $list.Update()  
          Write-host " **Item Added** `n" -foregroundcolor green  
          $views = $list.Views["All Items"];  
          $views.ViewFields.Add($spFieldName);  
          $views.Update()  
        }  
     }  
   }  
   else{Write-Host "No List Found"}  
 }  

--
Regards,
Praveen Pandit


June 28, 2013

best way to get string, how to get value from Url C#

How to get Query string value, how to get values from url query with validation and best practice.

public int ItemID
{
get
{
if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Length > 0)
{
return Convert.ToInt32(Request.QueryString["ID"]);
}
else return 0;
}
}



Thanks,
Praveen Pandit
MCTS; MCPD
Keep Sharing Knowledge!!