Wednesday, December 17, 2014

Item Update vs SystemUpdate

Recently there was a need to update documents/ list items without creating new version and updating 'Modified' and 'Modified by' values.  Lists and Libraries were having event receivers or workflows. There are couple of options to update SPListItem and need to understand the differences between them. 
Update()
·        Updates the item in the database.
·        Updates the 'Modified' and 'Modified by' values.
·        Creates a new version
Systemupdate()
·        Updates the item in the database.
·        No changes in the 'Modified' and 'Modified by' values.
·        No new version.
·        Triggers the item events.
Systemupdate(true)
·        Same as Systemupdate() and it increments item version.
·        Using SystemUpdate(false) is same as SystemUpdate().
UpdateOverwriteVersion()
·        Updates the item but does not create a new version.
·        Updates the  'Modified' and 'Modified by' values.
you could set EventFiringEnabled = false to disable the triggering of events (workflows). Set EventFiringEnabled = true after item update to enable the events again. 

Friday, October 31, 2014

Delete a Timer Job in SharePoint

I was looking for a custom timer job that was having two instances. Second instance got created after another deployment. Feature deactivation did not delete the existing job. I wanted to delete old timer job but there is not option to delete that in central Admin. PowerShell help me out on that. PowerShell’s Get-SPTimerJob command provides listing of all the timer jobs.

When I run this command it was truncating the name and ids. To see all jobs with full name we need to change the buffer Size property of PowerShell window to 250+

Get-SPTimerJob |Format-Table id,name

To narrow down the results I used where clause with name with these properties to distinguish old job.

Get-SPTimerJob | where { $_.name -like "<JobName>" }| Format-Table  -autosize -Property LastRunTime,id,name,DisplayName,Status,ErrorMessage

After finding the id of correct Job, run these commands to delete the job.


$job = Get-SPTimerJob -id <Job's GUID>
$job.Delete()

Job will be deleted. you can confirm running above Get-SPTimerJob PowerShell command or in CA. 

Monday, October 6, 2014

SharePoint Designer - Run as different user

Recently I need to run SharePoint designer as different user. 'Run as different user' option is not available on SharePoint Designer shortcut.

Follow these steps to start SharePoint Designer 2010/ SharePoint Designer 2013 as another SharePoint user

1.      Search for SPDESIGN.exe in windows explorer. you will find this under these locations based on version of SharePoint Desginer you have. 
               SharePoint Designer 2013(64bit) - C:\Program Files\Microsoft Office\Office15
               SharePoint Designer 2013(32bit) - C:\Program Files (x86)\Microsoft Office\Office15
               SharePoint Designer 2010(32bit) - C:\Program Files (x86)\Microsoft Office\Office14
2.      Press and hold the Shift key, right-click SPDESIGN.exe, and then click Run as different user.
3.      Type the credential of the user and then click OK.

Or

You could Log on to Windows by using another user account, and then run SharePoint Designer.

Tuesday, September 30, 2014

Add FileType Icons in SharePoint

Sometime when you upload a file in document libraries and icon doesn’t appear in 'Type' column. That is because SharePoint does not provide icons for all kinds of FileTypes. However SharePoint is flexible enough that you could add a new icon for missing FileType.

Note: You need to perfrom these steps on each Web Server you have. for SharePoint 2013 these changes made in 14hive not 15hive.

To add Icon you need to find or create an icon for that FileType (16 x 16 Pixel gif or png) and copy it to
..Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES (for SharePoint 2013 as well not in 15hive)
Next step is to edit Docicon.xml ( don't forget to take the backup of Docicon.xml before edit). This file is present in
..Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML
Search for <ByExtension> section and add an entry for file extension of the application like this 
<Mapping Key="zap" Value="iczap.gif" />
Do IISReset. 
You should see the Icon now. HTH..

Thursday, September 18, 2014

Extract WSPs from Central Admin Solution Management

You can extract wsps from Central Admin Solution Management using PowerShell if you don't have binary or Setup exe.

$wsps = "Solution1.wsp;Solution2.wsp"
$path = "D:\Wsps\"

$farm = Get-SPFarm
$wspNames = $wsps.split(";",[StringSplitOptions]'RemoveEmptyEntries')
foreach($wspName in $wspNames) {
$file = $farm.Solutions.Item($wspName).SolutionFile
$file.SaveAs($path+$wspName)
Write-Host "Solution File extracted to this location " + $path$wspName
 }


Wednesday, April 16, 2014

Save site as Templete using PowerShell

You can create site template using SharePoint site setting UI. alternatively you could PowerShell

$Web=Get-SPWeb http://sp2013.com/sites/template
$Web.SaveAsTemplate("Template Name","Template Title","Template Description",1)

If you want to save specified site as template along with data use 1, otherwise use 0 in forth parameter of SaveAsTemplate().

After running above commands, the newly created template will be available in site collection "Solutions" gallery.

ReDeploy Custom Timer Job using PowerShell

Following are the steps you need to redeploy a custom timer job.

Disable-SPFeature -Identity "91b81920-cc93-46da-b2c9-7e29c5077a67" -Url "http://sp2013.com/"
UnInstall-SPFeature -Identity "91b81920-cc93-46da-b2c9-7e29c5077a67"

Uninstall-SPSolution -Identity TimerJob.wsp –allwebapplications
Remove-SPSolution TimerJob.wsp –force

Add-spsolution C:\temp\TimerJob.wsp
Install-spsolution TimerJob.wsp -GACDeployment –force

Enable-SPFeature -Identity "91b81920-cc93-46da-b2c9-7e29c5077a67" -Url "http://sp2013.com/" –PassThru

Stop-Service SPTimerV4
Start-Service SPTimerV4

If you use update solution TimerJob may not pickup updated functionality
//Update-SPSolution -Identity timerjob.wsp -LiteralPath C:\temp\TimerJob.wsp -GACDeployment