Skip to main content

Posts

Showing posts from 2012

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.(SharePoint 2010 Powershell error)

Error:- "The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered when trying to run SharePoint 2010 PowerShell"

This message would also show up if you try to run the SharePoint 2010 Managment Shell without the proper permissions, or if the account does not have the proper permissions in SQL

OR



Modify XSLT for discussion board page SharePoint 2010

If you edit Discussion Board page in SharePoint, You can provide link to xsl file to change the look and feel of the page:-




You can refer to default XSL used by this page(thread.xsl)
Path:-
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL

C# Delegate to perform asynchronous method calls

Paste below code inVS 2010 console application: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProjectDelegateAsync
{
classProgram
{
publicdelegatevoidLongTimeTask_Delegate(string s);
publicdelegatevoidLongTimeTask_Delegate1(string s);
staticvoid Main(string[] args)
{
LongTimeTask_Delegate d = null;
d = newLongTimeTask_Delegate(LongTimeTask);

IAsyncResult R = null;
R = d.BeginInvoke("TestString", null, null); //invoking the method

LongTimeTask_Delegate1 d1 = null; d1 = newLongTimeTask_Delegate1(LongTimeTask1);

IAsyncResult R1 = null; R1 = d1.BeginInvoke("TestString", null, null); //invoking the method

Console.WriteLine("last line of program"); Console.ReadLine(); } publicstaticvoid LongTimeTask(string s) { for (int i = 0; i < 100; i++) { Console.Write(" i:" + i); } } publicstaticvoid LongTimeTask1(string s) { for (int i = 0; i < 100; i++)

Disable List Deletion sharepoint 2010

If you don’t want users to be able to delete a specific SharePoint 2010 list, you can disable list deletion using Windows PowerShell. The example below demonstrates how to disable deletion of the tasks list on a Web site:


PS > $spWeb=Get-SPWebhttp://SP01.powershell.nu PS > $spList=$spWeb.Lists["Tasks"] PS > $spList.AllowDeletion=$false PS > $spList.Update() PS > $spWeb.Dispose()
source:-secretsofsharepoint.com

Versioning of Visual Studio SharePoint Workflow

This article is copy of
Phil Wicklund'sbook of SharePoint Workflow

Thanks to him for solving biggest problem of Sharepoint State Machine Workflow.



You built this compelling Visual Studio workflow and deployed it into production.
But, after a few months, the business requests a small change to the workflow. You go
back into the workflow code, add a few activities to fulfill the request, and redeploy
the workflow into production. To your shock, all the workflows start breaking! You’re
frantic because you’re certain you adequately unit-tested the changes and can’t figure
out what might be going wrong. You didn’t version your workflow.
Workflow versioning is an important technique. When a workflow goes idle, the
state of the workflow is saved into the database. This saving of a workflow’s state is
called hydration. When the workflow resumes, the state is dehydrated out of the database,
and the workflow starts processing again. Versioning is important because, if you
change the assembl…

Add Custom button to SharePoint ribbon with server side code to execute

To add custom button to ribbon we will need to do below things:-
1.Create SharePoint Empty Project.
2.Add new “Empty Element”.
3.Map Layout folder.
4.Add One JS file to Layout folder.
5.Add Application Page to same folder.
6.Crete 2 logo images

Look at below solution Structure:-


Output:-


Custom button will be enabled only when item is selected:-

Code:-



Customize SharePoint Content Editor Web Part in VS 2012 classic webpart

1. Paste below code in cs file of classic web part(Not visual web Part)

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace POC2012CEWP.MyClassicCEWP
{
    [ToolboxItemAttribute(false)]
    public class MyClassicCEWP : Microsoft.SharePoint.WebPartPages.WebPart
    {
        private string _content;
        private HtmlGenericControl editableRegion = new HtmlGenericControl();
        private HtmlGenericControl emptyPanel = new HtmlGenericControl();
        private bool IsInEditMode
        {
            get
            {
                SPWebPartManager currentWebPartManager = (SPWebPartManager)WebPartManager.GetCurrentWebPartManager(this.Page);
                return (((currentWebPartManager !…

Sharepoint designer Cannot perform this operation. The file is no longer checked out or has been deleted

"Cannot perform this operation. The file is no longer checked out or has been deleted."
 SharePoint Designer is out of sync with SharePoint and you have to delete its cache in order to rebuild it. The cache is composed of these 2 folders:
%APPDATA%\Microsoft\Web Server Extensions\Cache%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
Open the folders and delete all cache data


You can try saving below code in .bat file and running it


cd "%APPDATA%\Microsoft\Web Server Extensions\Cache"
del *.web /S /Q "%APPDATA%\Microsoft\Web Server Extensions\Cache"
cd "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\"
rmdir /S /Q "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache\."
mkdir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache"
dir "%APPDATA%\Microsoft\Web Server Extensions\Cache"
dir "%USERPROFILE%\AppData\Local\Microsoft\WebsiteCache"
pause

Enable/Disable Developer Dashboard Powershell command SharePoint 2010

Type below commands in Powershell

$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$addsetting.Update()


Make it OnDemand


$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$addsetting.Update()


Turn Off

$service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$addsetting =$service.DeveloperDashboardSettings
$addsetting.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::Off
$addsetting.Update()

Make Column Read Only Sharepoint 2010

PS C:\Users\gadekasa> $spWeb = Get-SPWeb http://abc:5552/sites/AirCraft/
PS C:\Users\gadekasa> $spList = $spWeb.Lists["AllWorkflowDefaultList"]
PS C:\Users\gadekasa> $fields =$spList.Fields["Role"]
PS C:\Users\gadekasa> $fields.ReadOnlyField = $false
PS C:\Users\gadekasa> $fields.update($true)
PS C:\Users\gadekasa> $spList.Update()
PS C:\Users\gadekasa> $spWeb.Dispose()