开发者

Customizing Document library web part

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 开发者_如何学Goadd 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.


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..
}
  • Link for $.url.decode
  • Link for getParameterByName
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜