Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

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

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

Tuesday, November 12, 2013

SharePoint Form Fields and jQuery

Get or Set values/attributes of SharePoint Form Fields using JQuery.


Question 1: From where to download JQuery Base Library?
Answer 1:  http://code.jquery.com/
Question 2: How to include JQuery Script?
Answer 2: Upload the JQuery base library to the Assets list and include the library using the below syntax
<script type="text/javascript" src="../../Assets/jquery-1.10.2.min.js"></script>
Question 3: What attribute to use for getting the INPUT object?
Answer 3: We need to use the 
title attribute of the INPUT control
<input name="ctl00$m$g_e2bcfa9c_6e16_4b44_9833_22e44201a72b$ctl00$ctl04$ctl03$ctl00$ctl00$ctl04$ctl00$ctl00$TextField" type="text" maxlength="255" id="ctl00_m_g_e2bcfa9c_6e16_4b44_9833_22e44201a72b_ctl00_ctl04_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_TextField" title="Email" class="ms-long" />
Question 4: How to write JQuery function?
Answer 4:
<script type="text/javascript" src="../../Assets/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
});
</script>
Note: $(document).ready(function ()... is referred as the MAIN() function
Question 5: How to get the value of the INPUT field?
Answer 5: var variablename = $("input[title='title of the input control']").val();
Question 6: How to make the field readonly?
Answer 6: $("input[title='title of the input control']").attr("readonly","true");
Question 7: How to get the value of the Dropdown?
Answer 7: var variablename = $("select[title='title of the dropdown control']").val();
Question 8: How to set the value to the text field?
Answer 8: $("input[title='title of the input control']").val("enter value here");
Question 9: How to remove the readonly of the text field?
Answer 9: $("input[title='title of the input control']").
removeAttr("readonly"); 
Question 10: How to set focus to the text field?
Answer 10: $("input[title='title of the input control']").
focus(); 
Question 11: How to use JQuery in PreSaveAction or PreSaveItem?
Answer 11: 
<script type="text/javascript" src="../../Assets/jquery-1.10.2.min.js"></script>
<script language = "Javascript">
function PreSaveAction() 
{
var variablename = $("input[title='title of the input control']").val();
}
</script>
Note: do not include $(document).ready(function ()... 
Question 12: How to call JQuery function in Dropdown value change?
Answer 12:
<script type="text/javascript" src="../../Assets/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("select[title='title of the control']").change(function () {
//write logic here
});
});
</script>
Question 13: How to set the width of the Text field?
Answer 13: $("input[title='title of the control']").width(100);
Question 14: How to disable Textfield?
Answer 14: 
$("input[title='title of the control']").attr('disabled','disabled');
Question 15: How to Remove disable attribute on Textfield?
Answer 15: 
$("input[title='title of the control']").removeAttr('disabled');
Question 16: How to check numeric value in Text field?
Answer 16: 
var numbervaluefield = $("input[title='title of the control']").val();
var numericheckvaariable = $.isNumeric(numbervaluefield);
Note: The function will return boolean value
Question 17: How to compare date in Jquery?
Answer 17:
var startdate = new Date($("input[title='Start Date']").val()); 
var enddate = new Date($("input[title='End Date']").val());
if(enddate < startdate)
{
 alert("End Date cannot be lesser than Start date.");
 $("input[title='End Date']").focus();
 return false;
}
else
{
 return true;
}
Question 18: How to set default value in Rich Text field?
Answer 18:
<script type="text/javascript" src="../../Assets/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

var htmlcontentval = "<table border='1' cellpadding='0' cellspacing='0'><tr><td colspan='3'>Month-Year</td></tr><tr><td>Milestone</td>       <td>Onsite Effort</td><td>Offshore Effort</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>";
$("textarea[title='Milestone Information']").val(htmlcontentval);
});
</script>
Note: Milestone information is the title of the textarea used in the Rich text field
Question 19: How to hide the Sharepoint Enhanced Richtext field?
Answer 19:  $("textarea[title='richtexttitle']").closest("tr").hide();
Question 20: How to unhide the Sharepoint Enhanced Richtext field?
Answer 20:  $("textarea[title='richtexttitle']").closest("tr").show();
Question 21: How to convert string to uppercase?
Answer 21:  $("input[title='titlename']").val().toUpperCase();
Question 22: How to check length of the string?
Answer 22 : $("input[title='titlename']").val().val().length;
Question 23: How to validate Email address?
Answer 23:
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 
var emailaddressVal = $("input[title='titlename']").val(); 
if(!emailReg.test(emailaddressVal)) 
{
 alert("Please enter valid email address");
}
Question 24: How to prevent free email addresses like yahoo.com, gmail.com ?
Answer 24:
var emailblockReg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $("input[title='titlename']").val(); 
if(!emailblockReg.test(emailaddressVal)) 
{
 alert("Free Email addresses are not allowed");
}

Question 25: How to get the lookup text value (Dropdown text value)?
Answer 25: $("option:selected", $("select[title='titlename']")).text();


Monday, June 17, 2013

List and Library templates missing from SharePoint sites

Recently i came across an issue where users don't have default Library and list templates to choose from when they want to create a list or library.

Issue -
When user selects 'More options' from site actions menu and select filter by:
Library - It shows only three templates Asset, Slide and wiki page Library.
List - It shows only one template 'Import Spreadsheet'.

Solution -
Team collaboration Lists feature provides team collaboration capabilities for a site by making standard lists, such as document libraries and issues, available. so if you encounter such issue just make sure Team collaboration Lists feature is activated on the site.

Go to Site settings -> Manage site features -> find 'Team Collaboration Lists' feature -> Activate

Tuesday, May 28, 2013

Target Audience - non-existent membership Group

While working with User Profiles Service and Target Audience I noticed that members are not showing up in Audiences. There are the possible areas to look for reasons -

- Check group is present in AD.
- Look for Group with same name (duplicate group).
- Check service account permission on Active Directory (OU).
- Check the User Profile Synchronization connection. Make sure Sync connection includes the OU's where groups are located.
 UPApp > Syncronization> Configure Synchronization Settings > Option "Users & groups" is selected, run a Full Sync
- If Full sync is not working then Check User Profile Synchronization Service. (Stop and Start with correct Credential to fix any FIM issues - IISreset required after User Profile Synchronization Service started)
- Compile the audiences after Full Sync.
- Check if Audience shows Users in view membership.
- Check Audience Rules if Audience rule throws error.
- Check Groups are present in UPA "Profile DB" post Full Sync.

Run the following queries against Profile DB of the to see if group is present or not

Select * from MemberGroup (nolock) where AllWebsSynchID is NULL -- It should fetch all AD groups
Select * from MemberGroup (nolock) where AllWebsSynchID is NULL and DisplayName like '%group name%'

Also if you are uploading audiences using PowerShell Script then make sure you are using Active Directory Group's full path in Value option in reverse hierarchy not just Group Name.

<Rule Property='DL' Operator='Member of' Value='CN=GroupName,OU=Groups,OU=ABC,DC=Domain,DC=com' />

Saturday, May 11, 2013

SharePoint Development Tools

Recently I came across with SharePoint Software Factory. It is a Visual Studio Extension helping SharePoint newbies, as well as experienced developers to create, manage and deploy SharePoint solutions without having to know every tiny XML and C# secret.
SPSF provides a huge collection of helpful recipes for development, debugging and deployment of SharePoint standard artifacts and is fully compatible with SharePoint 2007/2010/2013 and Visual Studio 2008/2010/2012.
This extension can cut your development time tremendously. I would highly recommend it for SharePoint developers.
SharePoint Software Factory - http://spsf.codeplex.com/

Wednesday, September 12, 2012

Hide a column from List Edit Form



I wanted to hide a column from Edit form of a specific list   

function Hide-SPField([string]$url, [string]$List, [string]$Field) {
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
 $OpenWeb = $SPSite.OpenWeb()
 $OpenList = $OpenWeb.Lists[$List]
 $OpenField = $OpenList.Fields[$Field]
 $OpenField.ShowInNewForm = $True
 $OpenField.ShowInEditForm = $False
 $OpenField.ShowInViewForms = $True
 $OpenField.ShowInDisplayForm = $True
 $OpenField.Update()
 $SPSite.Dispose()
 $OpenWeb.Dispose()
 }

 Hide-SPField -url http://yoursite.com/ -List "ListName" -Field "ColumnName"

If you want to hide column in forms across the entire site. you need set the PushChangesToLists property for the changes to be applied to lists where the column has already been added.




#Get the web and site column objects
 $web = Get-SPWeb "http://yoursite.com
 $column = $web.Fields["ColumnName"]
$column.PushChangesToLists = $true
 #Change the ShowInForm property and update objects
 $column.ShowInEditForm = $False
 $column.ShowInNewForm = $False
 $column.ShowInViewForms = $False
 $column.ShowInDisplayForm = $False
 $column.Update()
 $web.Update()
 $web.Dispose()





Move Site Collections between Content Databases



In MOSS 2007 one of content database has grown beyond 100 GB. So I wanted to move couple of existing site collections to another content DB. So I used STSADM to move them.

You can retrieve all the site collections from the source content database using this stsadm command. It will generate a file sites.xml.
stsadm -o enumsites -url http://webAppURL/ –databasename Your_Content_DB > sites.xml

Open sites.xml and remove the sites that you keep in source database. You need to keep site collections entry that you want to move to destination content database. Save the file.
Now run this command to move site collections to another content database.
Merge databases:
stsadm -o mergecontentdbs -url http://webAppURL/ -sourcedatabasename <SourceDB>  -destinationdatabasename <DestinationDB> -operation 3 -filename mysites.xml

In SharePoint 2010 we can achieve the same using PowerShell.
Move-SPSite <URLofSiteColletion> -DestinationDatabase <DestinationDB>