Tuesday, March 15, 2011

Show Quick Launch Menu on SP Web Part Pages

 

This is a very common requirement faced by almost every SharePoint Developer. I was in dilemma whether to put this post or not thus, kept in bay this topic for a while. Smile   Then today I finally decided to add this in to my blog posts.

When we create new web part pages, the page provides the option of adding new web parts inside the specified web part zones. When I tried to create such page with Quick Launch menu, I did not get any option to activate or add the Quick Launch menu by editing the page.

clip_image002

When we create new page, we select a page templates. SharePoint creates new page based on our selected page template and hides all other page elements that are not included in the selected page template. For SharePoint it is always the same page definition and master page, thus the basic structure is always there in the page. We can better understand this if we open the page in the SharePoint Designer. We could see many content place holders which are there in the page but are not visible when the page gets populated. The quick launch menu is placed inside the Place Holder Left Nav Bar (hover over the bottom left side, usually where the quick launch menu remains).

clip_image004

Click the pointer and select Default to Master’s Content

clip_image006

Would get this prompt, click YES

clip_image008

And you could see that the quick launch menu gets visible. Save the page and you are done.....

clip_image004[1]

If you have a more elegant solution – please post a comment… I’ll be happy to hear.

HaPpY CoDiNg... (Aurum)

Sunday, March 13, 2011

Hide "New" document menu item from document library

 

Recently I had to face this requirement of hiding the New from Document Library. I generally disapprove changing the basic functionality/behaviour of SharePoint. At times you have to scratch your head while this kind of changes make SharePoint go crazy and starts behaving erratically.

All these said and done.. I had to implement the requirement.. and the document library was only left with upload option.

Sometimes we can hide the New option by restricting the users with only Read/View permission, but that will also take away the Upload option...

Like a good SharePoint-boy I immediately thought my solution will be creating a new feature that uses the tag for hiding different menu items in SharePoint.

To my surprise I learned that the “new” menu item in the list view web part tool bar is not listed as a in any feature, so it cannot be removed as so.

Finding no other choices, I added a Content Editor Web Part in the Document, created this JS code and added in the Source Editor.

First edit the page by clicking Site Action and the Edit Page

image

Then add a Content Editor Web Part at the same web part zone of the list view.

image

Now modify the web part and get to the source editor and the following JavaScript code.

<div id="Tt" onload="HideNewMenuItem();">

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("HideNewMenuItem");

function HideNewMenuItem() {

//alert('test script');

try {

if (ctx) {

if (ctx.listBaseType == 1) {

var tables = document.getElementsByTagName("table");

for (var i = 0; i < tables.length; i++) {

if (tables[i].id.indexOf("NewMenu") > 0) {

var element = tables[i];

element.parentElement.parentElement.style.display = "none";

element.parentElement.parentElement.nextSibling.style.display = "none";

} } } } }

catch (e) { }

}

</script>

</div>

The _spBodyOnLoadFunctionNames.push("HideNewMenuItem");add this custom javascript method the on load function collection. The js will not fire if this is not added.

This checks if the current page has a document library view and if so – locate and hide its “new” menu item…

image

Save it and see the New Menu is gone... Viola....

image

If you have a more elegant solution – please post a comment… I’ll be happy to hear.

HaPpY CoDiNg... (Aurum)