Posts

AllowUnsafeUpdates VS RunWithElevatedPrivileges

AllowUnsafeUpdates:  If your code modifies Windows SharePoint Services data in some way, you may need to allow unsafe updates on the Web site, without requiring a security validation. You can do by setting the AllowUnsafeUpdates property. PList list= web.Lists["MyList"]; SPListItemCollection items= list.GetItems(); web.AllowUnsafeUpdates = true; foreach (SPListItem item in items) {      item["Title"] = "New Title";      item.Update(); } web.AllowUnsafeUpdates = false; RunWithElevatedPrivileges :  There are certain object model calls model that require site-administration privileges. To bypass access-denied error, we use RunWithElevatedPrivileges property when request is initiated by a nonprivileged user. We can successfully make calls into the object model by calling the RunWithElevatedPrivileges method provided by the SPSecurity class. SPSecurity.RunWithElevatedPrivileges(delegate() {     using (SPSite site = new SPSit...

sharepoint timer job run on specific server

Timer jobs are wonderfully robust creatures. They effectively replace the "Windows Scheduled Task" for SharePoint servers, allowing you to run .Net code on a scheduled or "one off" basis. However, there can be some confusion about running Timer Jobs on multiple servers, so this should clear it up a bit. By default Timer Jobs will only execute on the server that they are called from (typically the Central Administration server) Through code you can specify a specific box (SPServer) to run your Timer Job on. It is possible to run a Timer Job on every server on the farm (although this can be dangerous!) The crux of all this is based on the SPJobDefinition constructor ( http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spjobdefinition.spjobdefinition.aspx ). The constructor includes a parameter for an  SPServer object , which  allows you to specify which server the timer job will run on . Example Code 1 – Add Job to single ...

Power Sell Admin Commands

Add-SPSolution c:\code\SharePointProject2\bin\debug\SharePointProject2.wsp Install-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 -GACDeployment Update-SPSolution –Identity youreWSPName.wsp –LiteralPath C:\Solutions\youreWSPName.wsp –GACDeployment Uninstall-SPSolution –Identity SharePointProject2.wsp –WebApplication http://sp2010 Remove-SPSolution –Identity SharePointProject2.wsp Get-SPFeature Get-SPFeature –Site http://sp2010 Get-SPFeature –Identity Reporting –Site http://sp2010 Enable-SPFeature –Identity Reporting –url http://sp2010 Disable-SPFeature –Identity Reporting –url http://sp2010 /****************** BACKUP and Restore Site Collection ******************/ Backup-SPSite -Identity http://testSite/sites/orf/ -Path "c:\backup\file.bak" Restore-SPSite -Identity http://Servername:port -Path "c:\backup\file.bak" -force /****************** BACKUP and Restore Site Collection ****************** /******...

Sharepoint Web Part tabbing

<!-- Reference the jQueryUI theme's stylesheet on the Google CDN. Here we're using the "Start" theme --> <link  type="text/css" rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/start/jquery-ui.css" /> <!-- Reference jQuery on the Google CDN --> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <!-- Reference jQueryUI on the Google CDN --> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script> <script type="text/javascript">      jQuery(document).ready(function($) {          //Put the Web Part Title for all the Web Parts you wish          //to put into the tabbed view into the array below.         WebpartTabs(["Web Part Title 1","Web Part Title 2"]);     });     f...

Creating SharePoint 2010 State Machine Workflows in Visual Studio 2010

Image
Microsoft Visual Studio 2010 provides a State Machine Workflow template that enables you to build workflow solutions for Microsoft SharePoint 2010 by using a graphical design surface. Unlike sequential workflows, which transition from activity to activity, state machine workflows transition from state to state. This SharePoint Visual How To describes the following steps for creating and deploying a state machine workflow to a SharePoint 2010 site: Creating a prerequisite document library named Projects. Adding state activities for  stateInProgress ,  stateReview , and  stateFinished . Configuring state initialization and events for each state. Configuring code that determines state transitions. Prerequisites This workflow requires a specific document library named Projects. To create the Projects document library On the  Site Actions  menu, click  More Options . In the installed items list, click  Document Library . O...