Just little about C#, .NET, SQL Server, SharePoint and SAP

Archive for October, 2010

Hiding links using jQuery in SharePoint

Posted by zieglers on October 22, 2010

If you want to hide links, tables, and elements on a SharePoint site without touching its functionality, there is a clean way doing so using jQuery.

Let’s say you want to remove some links on create.aspx page or on your home page of your SharePoint site. You can do this as follows: (assuming that you already host your jquery-1.*.*.min.js file somewhere in your site or in layouts folder)

1. Create a feature, which adds a control to a page.

2. Render this control on every page

3. Use jQuery to find and remove links you want.

For example, below code will remove Recycle Bin from quick launch menu only on home page.

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

    if (location.href.indexOf(‘default.aspx’) >= 0) {

        $(document).ready(function() {





Now, once you activate your feature, it’ll render above control on everypage and based on your if clause in the script, you can hide any link, table, element you want on any page.

P.S. try this with table.ms-main and see what happens!!!


Posted in IT Stuff, SharePoint | Leave a Comment »

Adding a document type in New Document drop down

Posted by zieglers on October 6, 2010

Have you ever tried to add an extra document template to New button in a SharePoint library, and realized that you can’t do this unless you add another content type to that library?

In other words, you want your users to be able to create more than one document type in a library, but you don’t want to use multiple content types on that library.

Here is a way how you can do it…

Trick is using javascript in UrlAction. But specifically there is one function you have to use, which is createNewDocumentWithProgID.

In this example, i’ll show you how to add, say create Excel sheet button, in addition to Word.

1. Specify a location for your document template. For instance, {SiteUrl}/_layouts/DocTemplates/Book.xls

Put your document templates in that location, or in your feature make sure that your document templates are provisioned to that location.

2. Create a feature for your new CustomAction, which will host our javascript in its UrlAction. Use following CustomAction code in your elements.xml.


<?xml version=”1.0″ encoding=”utf-8″ ?>
    Title=”Create New Document Drop Down”
    Description=”Adds document types to the New Document dropdown menu.”
    <ElementManifest Location=”elements.xml” />


<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=http://schemas.microsoft.com/sharepoint/ >
  <!– Document Library Toolbar New Menu Excel –>
  <CustomAction Id=”DocLibNewToolbar”
    Rights =”AddListItems”
    Description=”Creates a new Microsoft Excel Document”
    Title=”Microsoft Excel Document”>
    <UrlAction Url=”…JavaScript goes here…“/>
</Elements >

3. Put below script in url attribute of UrlAction.



var templateurl = GetTemplateName();

function GetTemplateName()
 var templatename ='{SiteUrl}/_layouts/DocTemplates/Book.xls’;
 return templatename ;

var libraryurl = getLibraryName();

function getLibraryName()
 var URL = window.location.toString();
 var lname = URL.split(‘/’);
 var forms = 0;
 var viewname = lname[lname.length-1];

 if (lname[lname.length-2] == ‘Forms’)
  forms = lname[lname.length-2].length;
 var Lurl = URL;
 Lurl = Lurl.substr(0,Lurl.length-viewname.length-forms-1);
 return Lurl;

createNewDocumentWithProgID(templateurl, makeAbsUrl(libraryurl),’SharePoint.OpenDocuments’, false);



Posted in IT Stuff, SharePoint | Tagged: , , , , , , , , | Leave a Comment »