Thursday, 30 August 2012

Export SharePoint List data into CSV file

Hi,

I have found couple of blogs explaning the reverse way of expoting csv file data into SharePoint list. I have accomplished the other way around and hence thought of sharing this with you.

InOrder to export data from SharePoint list into CSV file, lets first query SharePoint list and get the required items and then we will export these items into CSV file.


$spSiteUrl = "http://sharepointwebapplication"
$listtitle="My Custom List"
$spWeb= Get-SPWeb -Identity $spSiteUrl
Function ImportDataFromListToCSV
{
  IF($spWeb -ne $null)
  {
  $list = $spWeb.Lists.TryGetList($listtitle)
  $exportlist = @()
  $items = $list.Items
  Write-Host "Exporting........" -ForegroundColor Yellow
  if($items -ne $null)
  {
    #Here "givenName" column name for CSV file and "Given Name" column name SharePoint List
    $items | %{ select-object -input $_ -prop @{Name='givenName';expression={$_["Given     Name"];}},@{Name='surname';expression={$_["Family Name"];}};}| Export-Csv -Path C:\Demo.csv -NoTypeInformation
    Write-Host "SharePoint list data is exported successfully." -ForegroundColor Green
    $spWeb.Dispose()
 }
 Else
 {Write-Host "No data found in the list "$listtitle -ForegroundColor Yellow}}
}

Enjoy PowerShell,
Isha Jain
 

Wednesday, 29 August 2012

SharePoint and PowerShell

I have realised the importance and power of PowerShell and hence thought about sharing.

These days I am working very deeply with PowerShell in SharePoint.

Sending an email using PowerShell...

Function SendMail
{
  $smtpServer = "your SMTP server name"
  $logFileName= "C:\test.txt"
  $att = new-object Net.Mail.Attachment($logFileName)
  $msg = new-object Net.Mail.MailMessage
  $smtp = new-object Net.Mail.SmtpClient($smtpServer)
  $msg.From ="test@gmail.com"
  $msg.To.Add("he@gmail.com")
  $msg.To.Add("she@gmail.com")
  $msg.Subject = "Test Mail"
  $msg.Body = "This is a test email.
  $msg.Attachments.Add($att)
  $smtp.Send($msg)
  $att.Dispose()
}

Power of SPQuery Object in SharePoint....

$spSiteUrl = "http://webapplication"
$spWeb= Get-SPWeb -Identity $spSiteUrl

Function EmptySPList
{ Param($listname)
  IF($spWeb -ne $null)
  {
   $list = $spWeb.Lists.TryGetList($listname)
   $caml=""
   $query=new-object Microsoft.SharePoint.SPQuery
   $query.ViewAttributes = "Scope='Recursive'"
   $query.Query=$caml
   $items=$list.GetItems($query)
   $items | % { $list.GetItemById($_.Id).Delete()  }
   Write-Host "Items from list '" $listname "' are deleted successfully." -ForegroundColor Green
  }}

Function FindSpecificSPListItems
{
 Param($list)
 $dateFrom=[Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Today)
 $dateTo=[Microsoft.SharePoint.Utilities.SPUtility]::CreateISO8601DateTimeFromSystemDateTime([DateTime]::Today.AddMonths(-3))
 $spQuery = New-Object Microsoft.SharePoint.SPQuery
 $spQuery.ViewAttributes = "Scope='Recursive'";
 $spQuery.RowLimit = 100
 $caml = '<Where><And><Leq><FieldRef Name="Date" /><Value  Type="DateTime">'+$dateFrom+'</Value></Leq><Geq><FieldRef Name="Date" /><Value Type="DateTime">'+$dateTo+'</Value></Geq></And></Where><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy>'
 $spQuery.Query = $caml
 $listItems = $list.GetItems($spQuery)
 if($listItems -ne $null)
 {
  #do some stuff
 }}

Cheers,
Isha

Saturday, 17 March 2012

Site Templates in MOSS 2007 and SharePoint Server 2010

The following are the list of Site Templates in MOSS 2007

Under Collaboration

  • Team Site (STS Template)
  • Blank Site (STS Template)
  • Document Workspace (STS Template)
  • Wiki (WIKI Template)
  • Blog (BLOG Template)
Under Meeting
  • Basic Meeting Workspace (MPS Template)
  • Blank Meeting Workspace (MPS Template)
  • Decision Meeting (MPS Template)
  • Social Meeting (MPS Template)
  • Multipage Meeting (MPS Template)
Under Enterprise
  • Document Center (BDR Template)
  • Record Center (OFFile Template)
  • Site Directory (SPSSITES Template)
  • Report Center (SPSREPORT CENTER Template)
  • Search Centre with Tabs (SPCHEN Template)
  • My Site Host (SPSMSITEHOST Template)
  • Search Center (SRCHCENTERLITE Template)
Under Publishing
  • Collaboration Portal
  • Publishing Portal (BLANKINTERNETCONTAINER Template)

The following are the list of Site Templates in SharePoint Server 2010

Under Collaboration
  • Team Site (STS Template)
  • Blank Site (STS Template)
  • Document Workspace (STS Template)
  • Blog (BLOG Template)
  • Visio Process Repository (VISPRUSTemplate)
  • Group Work Site (SGSTemplate)
Under Meeting
  • Basic Meeting Workspace (MPS Template)
  • Blank Meeting Workspace (MPS Template)
  • Decision Meeting (MPS Template)
  • Social Meeting (MPS Template)
  • Multipage Meeting (MPS Template)
Under Content and Data
  • Document Center (BDR Template)
  • Record Center (OFFile Template)
  • Business Intelligence Centre (BICenterSite Template)
  • Report Center (SPSREPORT CENTER Template)
  • My Site Host (SPSMSITEHOST Template)
  • PowerPoint Broadcast Site (POWERPOINTBROADCAST Template)
  • Personalisation Site (SPSMSITE Template)
Under Publishing
  • Enterprise Wiki (ENTERWIKI Template)
  • Publishing Portal (BLANKINTERNETCONTAINER Template)
Under Web Database
  • Asserts Web Database (ACCSRV Template)
  • Charitable Contribution Web Database (ACCSRV Template)
  • Contacts Web Database (ACCSRV Template)
  • Issues Web Database (ACCSRV Template)
  • Projects Web Database (ACCSRV Template)
Under Search
  • Basic Search Centre (SRCHCENTERLITE Template)
  • FAST Search Centre (SRCHCENTERFAST Template)
  • Enterprise Search Centre (SRCHCEN Template)
Below are the 10 newly added Site Templates and 4 removed Site Template List in SharePoint 2010

10  Newly Added Templates
  • Basic Search Centre
  • FAST Search Centre
  • Enterprise Search Center
  • Group Work site
  • Visio Process Repository
  • Charitable Contribution Web Database
  • Projects Web Database
  • Enterprise Wiki
  • PerformancePoint
  • Business Intelligence Center

4  Removed Templates
  • Site Directory
  • Search Centre with Tabs
  • Search Center
  • Collaboration Portal

Friday, 16 March 2012

Thursday, 8 March 2012

Yahoo! User Interface Library and Controls

YUI Library is a free open source JavaScript and CSS framework that helps in building rich interactive web applications.

More Information is available at : http://developer/yahoo.com/yui/

This library contains numerous controls like TabView,ProgressBar,Color Picker, TreeView etc.

The YUI TreeView control provides rich visual presentation of hierarchical data representation.

The following line of code will give the tree view output as shown below.



Cheers!!

Monday, 28 November 2011

Script to Automate the WSP deployment and to activate features

This post is regarding the usage of a simple script to automate the wsp installation and featue activation. Whenever we want to deploy components like custom web parts,  custom user control and custom application pages etc. we use sharepoint solution packages for deployment and then we activate the respective features manually. It is a tediou job to install the wsps and  activate the features manually, if we have multiple solution packages to be deployed. To automate this, we can use the the following script to install wsp and activate features.

 :begin
@echo off

set solutionName=Custom.MyTask
set SolutionPath=D:\Custom\Custom.MyTask.wsp
set featureSampleFeature1=Custom.MyTask
set featureSampleFeature2=Custom.MyTaskWPDeployment
set featureSampleFeature3=Custom.MyTask.WebConfigChange

rem ** Replace this value with the URL of your site **
@set url=http://vsalbtstwfe10:10110


@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%path%

stsadm -o retractsolution   -name %solutionName%.wsp -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %solutionName%.wsp -override

echo Adding solution %solutionName% to solution store...
echo ----------------------------------------------------

stsadm -o addsolution -filename %SolutionPath%
if errorlevel == 0 goto :deploySolution

echo ### Error adding solution %solutionName%
echo .
goto end

:deploySolution
echo Deploying solution %solutionName%...
echo ----------------------------------------------------
stsadm -o deploysolution -name %solutionName%.wsp -url %url% -immediate -allowGacDeployment -allowCasPolicies  -force
stsadm -o execadmsvcjobs

if errorlevel == 0 goto :activateFeature

echo ### Error deploying solution %solutionName%
echo .
goto end

:activateFeature

echo Activating feature %featureSampleFeature1% in solution %solutionName%...
echo ----------------------------------------------------

stsadm -o activatefeature -name %featureSampleFeature1% -url %url% -force

echo Activating feature %featureSampleFeature2% in solution %solutionName%...
echo ----------------------------------------------------

stsadm -o activatefeature -name %featureSampleFeature2% -url %url% -force


echo Activating feature %featureSampleFeature3% in solution %solutionName%...
echo ----------------------------------------------------
stsadm -o activatefeature -name %featureSampleFeature3% -url %url% -force

if errorlevel == 0 goto :success

echo ### Error activating features
echo .
goto end

:success
echo Successfully deployed solution and activated feature(s)..
echo .
goto end

:end
pause