views:

267

answers:

1

Hi,

I am developing a website in Sharepoint 2007. I came across a bit tricky problem. I have a document library web part in a web part page. I am using the summary toolbar view. I dont want users to add new documents on first screeen where it shows folders. I want them to open the folders and add documents there. I cannot do a No toolbar view because it will remove the link from every subsequent page. Has anyone implemented something like this. Please help.

+1  A: 

Event receiver to prevent adding item throught object model/web services or UI.

One solution would be to use event receiver and, if document is being added in root folder, just cancel adding document, but that would transfer user to error page. This solution is not user friendly.

Just hide the option to add new items

The other one would be to use javascript to hide new button document and upload document buttons. It's easy when you integrate SharePoint with jQuery.

Hide New Button

var newMenu = $('a[id$=NewMenu]').parents('.ms-toolbar') //Hides New button
if (newMenu[0] && newMenu[0].nextElementSibling.className == 'ms-separator')
  newMenu[0].nextElementSibling.style["display"] = "block" //Hides seperator between new button and next button.

But you probably would not like to completely hide the new button, but to leave creating new folder option.

$('ie\\:menuitem[id*=New]').not('[id$=NewFolder]').remove()

Hide Upload Menu

var uploadMenu= $('a[id$=UploadMenu]').parents('.ms-toolbar') //Hides New button
if (newMenu[0] && newMenu[0].nextElementSibling.className == 'ms-separator')
  uploadMenu[0].nextElementSibling.style["display"] = "block" //Hides seperator between new button and next button.

Ahh, forgot the (al)most important: check if you are on the RootDirectory.

var rootFolder = $.url.decode(getParameterByName("RootFolder"))
if (rootFolder && ctx && rootFolder.replace($.url.decode(ctx.listUrlDir+"/"),"").length == 0 ) {
  ..Do code above..
}
Janis Veinbergs
Hi janis, thanks a lot for the reply. My requirement is little different. I have a list web part set at "Summary toolbar" view. So I dont have the New/Upload/Settings menu options. I only have the "Add New Document" hyperlink. The webpart remaining same, I need to check from some falg that the current view only has folders and remove the "add new document" link accordingly. Please guide as per this requirement.
Sushant