How To Hide The Add Document Or Add New Item
Yesterday I won my MCC Award (Microsoft Community Contributor) and decided to add this entry as a special gift to the community. This is a simple workaround and I saw a request a couple days back asking to hide the Add Document link after the list of items. In fact, the Add Document may encourage users to upload files from their computers rather than use the create new (select content type). Plus, you still have the upload document or multiple documents from the ribbon. There are a few posts dealing with CQWP customization but most of them use the publishing pages. A few requests have been posted to customize blog posts using CQWP and there is something specific to this request: the CQWP does not output the blog post body out of the box. Before I describe the process, I should give credit to the blog post by Heather Solomon (2007, but still valid for 2010). SharePoint Manager (download from Codeplex) is a great tool for SharePoint Administrators. You have to install it on a front end server and run it as Administrator to be able to use it (also make sure you unlock the zip file before installation – basically unzipping the files and creating a default config file). The tool works as an object model explorer at the farm level and allows you to view properties and set some. You could, in principle, use PowewShell to accomplish similar tasks (if you know the commands and can do PS scripting), but SPM makes it easy and provides a GUI interface to do things – plus, it is free. Like several other posts, this one was inspired by a comment on my earlier post (Horizontal News Ticker Using SharePoint 2010 CQWP) and a question on SharePoint Forums about limiting the number of characters in the summary view of an announcements list. Usually the announcements Body field is rich text and if you try substring($thisNode/@Body,1,n) where n is the number of characters to display, you will end up with an html tag that may not get closed within the character limit. So, you need to strip the html tags first and this functionality is not available in SharePoint Designer. I wrote earlier about using a SOAP service to get an inventory of lists within a certain site. This post uses a different approach and can also be filtered for a particular type of list. So, if you need to view all task lists or calendars or document libraries or surveys or even external lists based on the __spBaseTemplate property.
There are a few ways to do that, one of which is using the browser only – add a CEWP and hide the link using CSS (see this thread for more). A similar approach is to use JQuery and hide the cell that has the Add Document link (again, you add a CEWP, reference the JQ library and add the script (something like $(document).ready(function() { $(‘#WebPartWPQ2 .ms-addnew’).hide();});). If you are doing this on the All Items view page, you will notice that the document library web part loses focus and you have to click inside to show the Library Tools ribbon and switching between views is not as easy as it should be. This is because we have two web parts in the page (even if you hide the CEWP, which you should any way – just check the Hidden property under Layout). It turns out there is another easy and better way – customize the xslt in SharePoint Designer. Select the library (site objects – lists and libraries) and click the view you want to edit (top right). If you want to modify the number of items per page, do it first: List View Tools – Options – Paging (this is not required but if you do it later you will overwrite your custom view).
Now highlight the text “Add Document” and from Design tab (under list view tools), Actions group, select customize item (click the arrow next to customize xslt). Then, switch to code view. The source view should increase by around 80 lines (starts with
Save your page in SPD and check it back in the browser. The Add Document is no longer visible and the view functions as usual.
Note1: If all you have is a web part, you can also set Toolbar Type to “No Toolbar” in the web part properties and that will remove the Add Document.
Note2: yesterday was also the release date for SharePoint Service Pack 1 (check this post from Spence Harbar before you install it)
Custom Blog Rollup Using Content Query Web Part
There are two main steps in this process: customize the ItemStyle and the CQWP. You can find the reference on adding properties to the CQWP at this MSDN article.
So, we export the CQWP and edit the line that has CommonViewFields to become
Here, Body is the post body text and Note is its type (yes, it’s not RichHtml as you may think), but how do we know? You check the schema file at \14\TEMPLATE\FEATURES\DiscussionsList\Discuss
Now that we have the field available in the CQWP, we edit the item style. The ItemStyle.xsl file lives in the Style Library in your site collection (only there, one style library per site collection) inside the folder XSL Style Sheets (that’s easy to figure out). You download the file and open it in a text or xml editor. Here, we will copy the default style and paste it under the original (starts with and ends with – around 67 lines). Of course, we need to name our style – I replaced the first line by You will notice we have a few blocks of xsl variables and I added my new one under the last one (Display Title)
We will get back to the removeMarkup soon (I used the same one by Heather).
The code starting with
just before the last
Finally, I added the template that strips out html tags right after the closing tag of my custom template (). The removeMarkup template is available from Heather’s post toward the end and is clearly marked.
Save the xsl file and re-upload to the styles library (xsl style sheets folder). You need to publish a major version for this to work (not only check it in).
Now, you add a web part to your page based on the exported and adjusted one (under the web part groups, locate the Upload web part then select from imported web parts). Configure your CQWP and select your new item style (do not add Body; in the Description field!). If you did not have typos, you should see something similar to the above screen shot. If your itemstyle is not correct, your CQWP will not show and will give error (add ?contents=1 to the url and delete it, then roll back to the previous version of the itemstyle until you fix the custom one). See more on Heather’s blog on how to see available fields and find types etc.
SharePoint Manager And Deleting The Drop Off Library
You have to explore the program to see what it offers. You can look at the object model on a minimal, medium or full scale. The navigation is divided into admin service (CA), content (web applications, sites and their contents), feature definitions, servers, services and farm solutions.
For example, you will see timer jobs or list count or list IDs (those GUIDs) and also feature IDs like saved web parts, but that’s not all. You can also set various (not all!) properties. I mention deleting the drop off library in the title (this is the document library that gets created when you activate the site feature: Content Organizer), but can’t we just do that from library settings in the browser? Actually, no. There is even no such link as delete this document library under library settings (for the drop off library settings – permissions and management).
In SPM, you browse to the site and select the library (under lists in the site tree), then change the Allow Deletion property to True. You can mediated delete the library then from SPM (right click and hit delete), but you can also do that from the browser after the property change.
You can also use SPM to delete sealed fields – those site columns that cannot be deleted (you create a custom content type or adjust an existing one – not a good idea) and add a site column to discover later that you can’t delete it. An example is the Byline column. In SPM, you navigate to site collection fields, select the field and set its All Deletion property to True and its Sealed property to False. You can also do that and remove them from dependent content types using Powershell (more on sealed columns in this blog post).
So, do not underestimate the power of SharePoint Manager and make sure you put it to a good use.The SPXSLT Project And How To Turn Announcements Into Marquee
Luckily, Marc Anderson, who maintains the SPXSLT project at Codeplex, had a ready xsl template which limits the Body to the first n words, which is even better. You should check Marc’s work and the SPXSLT project as it could save you plenty of time.
In a dataview web part, you can customize one item or the entire view (which could easily inject several hundred lines of XSL when you switch to code view). This is usually the same xsl that serves several types of lists. Sometimes, you only need a few lines to get your data in the rights format. Marc’s template is under 80 lines (including empty lines) and does even more than the standard one.
What you do (and this is for lists of type announcements) is to open the page that has the web part in SharePoint Designer, have the web part selected and from List View Tools (ribbon), Design tab, Customize XSLT (customize Entire View – click the drop down arrow to get there). Switch to code view and the block of code should be selected. Select the portion of code between
In this case, we don’t need the html manipulation or even the word count. I based my template on Marc’s but removed all table related markup, used and kept the Title field only. I also gave the
element the class name dfwp-list for no specific reason other than matching the class used by the CQWP (so earlier instructions work without modification). The rest is the same as outlined in the Horizontal News Ticker post.
Note: The @FileRef will not actually link to the item display form (this is how it reads in the original). To fix it, try to view one item from a standard announcements list and code the url accordingly. It should be something like: http://current-web-address/_layouts/listform.aspx?PageType=4&ListId=list-GUID&ID={@ID}&ContentTypeID=0x010400B0AC1F599DF7584FA331A0991AB8E6ED
You need to enter your own values for current web address and list-guid (without the braces!)
One more note: if you add your announcements as a dataform instead of xsltview, you can use the design group (dataview tools) and select a bullet list. In this case, you can link titles to the display form directly from the UI.
List Of All Lists In A Web Using ListOfLists DataSourceMode
The approach is fairly simple. Create a web part page in the relevant site and insert an empty data view (insert – data view – empty data view). You will get a link to select a datasource and you can select any list (in this example, the Links list was selected – random selection). You have a few fields selected in the data source details pane to the right, so you just select the “Insert selected fields as …” and choose Multiple Item View from the drop down (this is in the data source details pane near the top, select view/data source from the ribbon if the datasource is not visible). You should see some rows if the selected list is not empty.
Now, switch to code view (bottom left of the status bar) and locate the
You may notice something strange: a grid with several rows and no data inside. That’s ok. We’ll fix soon. While the dataform web part is selected, go to Add/Remove columns from the ribbon (data view tools – options tab). Remove the select fields (right side) and select a few of those starting with 2 underscores (__). Enlarge the image of the example to get a few to start with (I did not rename them for illustration, you should). In the Paging option (next to add/remove columns), select Display all items. That should give you a list of all lists (libraries included) within the site.
if you want just a specific type of list, click Filter (ribbon options) and then from the filter dialog, check add XSLT filtering and click Edit to add your filter. For example, use [@__spBaseTemplate='ExternalList'] to get only external lists.
You can adjust to dataform view, link lists or conditional format as you need, including the title of the web part which is named after your selected list by default. Notice that this works within one site (by default, the site you created the page in).