Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Archive for October, 2013

SharePoint 2010 – How to make a Site Collection Read-Only?

Posted by Paul on October 6, 2013

In this article, we can explore how to make a Site Collection read-only?

Why making Site Collection Read-Only?

During phases like development, requirement cut off, release the Administrator might require to make the Site-Collection read-only to prevent future add/edit/delete of contents.

What are the ways to make Site Collection Read-Only?

We can employ the following ways:

1. Central Administration by Administrator

2. PowerShell by Administrator

3. Server Object Model by Developer

Depending on the requirement, we can use the above 3 ways.

Let us explore all the 3 ways.

Create Site Collection

For playing with, I prefer you create a new site collection from Central Administration.

clip_image001

In the appearing page, enter the site collection details.

clip_image003

Open the site & ensure you can add contents.

clip_image005

Option 1: Making Read-Only through Central Administration

Go to Central Administration > Application Management > Configure quotas and locks

clip_image007

In the appearing page, choose the site collection & select the option Read-only.

clip_image009

Enter the lock information & Click the Ok button to continue.

Testing Read-only

Now we are ready to test the read-only functionality. Open the site collection main site & try adding a document. You should see the following error message.

clip_image011

This makes sure that you cannot add/edit/delete contents. The site is read-only.

Unlocking

Please go back to the Central Administration Lock Page & choose the Not locked option.

clip_image013

Now the site collection will be back to writeable mode.

Option 2: Making Read-Only through PowerShell

Now let us try the PowerShell option. Open SharePoint enabled PowerShell from start menu.

clip_image014

Enter the following command for locking the SharePoint site collection by URL.

Set-SPSite -Identity “http://hp/sites/sc2” -LockState “ReadOnly”

Testing Read-only

Open the site collection main site & try adding a document. You should see the same error message.

clip_image015

This confirms the site collection is now read-only.

Unlocking

No make the site back to writeable, use the following code in PowerShell window.

Set-SPSite -Identity “http://hp/sites/sc2” -LockState “Unlock”

Now the site collection will be back to writeable mode.

Option 3: Making Read-Only through Code

Now we can try the Server Object Model way of making site collection read-only.

Create a new console application, add reference to Microsoft.SharePoint assembly & execute the following code.

SPSite site = new SPSite(“http://hp/sites/sc2”);

site.ReadOnly = true;

Testing Read-only

Open the site collection main site & try adding a document. You should see the following error message.

clip_image011[1]

This confirms the site collection is now read-only.

Unlocking

No make the site back to writeable, use the following code.

SPSite site = new SPSite(“http://hp/sites/sc2”);

site.ReadOnly = false;

Now the site collection will be back to writeable mode.

clip_image017

Please note that there are 3 lock options:

· Read-Only where add/edit/delete of contents are prevented

· Adding content prevented where adding is prevented, but edit/delete is still possible

· No Access where even reading is prevented.

clip_image018

References

http://technet.microsoft.com/en-us/library/ff631148(v=office.14).aspx

Summary

In this article we have explored a real world scenario of making site collection read-only, through multiple options possible.

Advertisements

Posted in SharePoint, SharePoint 2010, SharePoint 2013 | Tagged: , , , | Leave a Comment »

Hide Version History in SharePoint 2010

Posted by Paul on October 3, 2013

In this article I would like to take you through a Real World Scenario. You wanted to hide the Version History menu item from the documents menu.

image

I am working on original code of Matthew Yarlett for the original code. Thank You Matthew for making things easier.

HideAction won’t work!

The typical HideAction way of hiding ribbon items won’t work with context menu items as they are rendered through JavaScript.

JavaScript Approach

The Version History menu item is residing in the Edit Control Block group of menu items. These menu items are rendered through the core.js java script file. The file resides in the _layouts folder.

We need to visit the file to find the Version History text & sequence number. The sequence number determines the position of menu item in the edit control block.

The file can be located in folder:

C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTS

Opening the core.js file & locating Version History text & use the L_Versions_Text variable to look ahead in file & locate the sequence number as 800.

image

JavaScript Code

Following is the JavaScript code which perform the hiding functionality.

ExecuteOrDelayUntilScriptLoaded(editEcbMenusEx, ‘Core.js’);

function editEcbMenusEx() {

try {

if (typeof ctx == “undefined”) {

return;

}

else {

    alert(‘ok’);

var css = ‘li[sequence=”800″]{display:none;}’;

var head = document.getElementsByTagName(‘head’)[0];

var style = document.createElement(‘style’);

style.type = ‘text/css’;

if (style.styleSheet){ style.styleSheet.cssText = css; }

else { style.appendChild(document.createTextNode(css)); }

head.appendChild(style);

}

} catch (e) {

}

}

Please note that the script is executed after Core.js is loaded.

How to test the code?

For testing the code, you need to perform the following steps:

1. Create a HideHistory.js file with above content & upload to Site Assets library

2. Edit the library page & add a content editor web part

3. Point the web part to our HideHistory.js file

image

4. Refresh the page

5. See the Version History menu item is hidden now

image

image

Please note that the hiding takes place in all libraries & lists where the content editor is placed. You need to add if condition to check for list template OR list name for conditional hiding.

If you need to apply to all pages without using Content Editor web part, you can add the code to master page. Please visit this link on how to do it.

References

http://bit.ly/GzKODY

Summary

In this article we have explored the way to hide Version History menu item in libraries.

The source code is attached here with.

Posted in SharePoint, SharePoint 2010, SharePoint 2013 | Tagged: , , , , , | Leave a Comment »

How to Deploy JavaScript to Master Page through Solution?

Posted by Paul on October 2, 2013

In this article I would like to take you through a real-world problem. You are working on a Java Script method which should be deployed to multiple SharePoint servers. The Java Script needs to be included in the Master Page file.

How to deploy it?

The manual deployment requires going to each SharePoint site, Opening the page in SharePoint Designer & Editing the master page. This way is time consuming & has maintenance overheads.

How to Automate Deployment?

We need to automate the deployment process. We can use the AdditionalPageHead delegate to render our custom code to master page & everything through automated deployment.

clip_image002

Steps

Please follow the steps below to achieve the following:

· Deploy Java Script page to SharePoint Master Page

Step 1: Create new project

Open Visual Studio & Create an empty SharePoint project & name it as MasterPageCode. Choose the farm solution option.

clip_image004

Step 2: Add User Control

Add a User Control item to the project & name it as MyControl. We are going to place our JavaScript code here.

clip_image006

In the appearing user control, place the following code which says Hello World through JavaScript.

alert(‘Hello World’);

The user control looks like below:

clip_image008

Now we need to include this user control code in the Master Page. We can achieve this in the next step.

Step 3: Add Deployment Element

Choose Add new item & select the Empty Element option & name it as MyAction.

clip_image010

Replace the content of file with following code. (please ensure the folder & file names are correct)

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<Control Id=”AdditionalPageHead” Sequence=”150″

ControlSrc=”~/_CONTROLTEMPLATES/MasterPageCode/MyControl.ascx”>

</Control>

</Elements>

Now the Solution Explorer looks like below:

clip_image012

Step 4: Deploy Solution

Now right click on the solution & choose the Deploy option. Wait for a few seconds & your solution will get deployed & activated automatically.

clip_image014

During runtime, the Java Script code will be appended to Master Page.

Step 4: Testing Solution

Open the default SharePoint site & you should receive the following JavaScript message box.

clip_image016

clip_image018

I thought of adding some important points:

1. The default master page of SharePoint pages is default.master & it resides in the 14 Hive > Templates > Layouts folder.

2. The AdditionalPageHead tag ensures the user control code is added to the master page. We can have multiple user controls rendered in this way.

3. The MyAction.xml file ensure the user control is deployed through the WSP file.

References

http://msdn.microsoft.com/en-us/library/ms470880(v=office.14).aspx

Summary

In this article we have explored a real world scenario. I hope the code will be useful in real word scenarios of integrating Java Script or Custom Controls to every page through solutions.

I have attached the source code along with.

Posted in SharePoint 2010 | Tagged: , , , , , , , | Leave a Comment »

Received Microsoft MVP for the second time!!

Posted by Paul on October 2, 2013

Thank You all for the supports.  I hope to serve you better. 🙂

Its a pleasure to be part of this positive, constructive, great team of leaders.

What is MVP Programme? Microsoft through MVP Programme enable people to share knowledge & become experts, helps other people to use the knowledge & ease their work life, helps themselves through faster solutions, Win-Win-Win solution!!

Posted in Uncategorized | Leave a Comment »