Archive

Archive for the ‘Web Parts’ Category

How To Disable Caching In CQWP

September 17th, 2011 Abed Khooli 1 comment

The Content Query Web Part is very useful for content aggregation and roll-up across the site collection scope. It was around in the previous version of SharePoint but has been improved in 2010 as can be seen in this MSDN Blog. There are, however, some inconveniences associated with it. CQWP may have issues with anonymous access as described here. The other issue which was discussed in this thread and also mentioned (2007) in this post is related to caching.
So, you configure a CQWP and apply some filtering. You test the results and they look OK. Then, you discover that new additions or updates are not reflected instantly – not even with a forced refresh, unless you try several times. You may go back to edit the web part and find that results are reflected immediately after an edit, but that’s not a solution.
The problem is related to caching which cannot be adjusted from the user interface. There are two workarounds: either export the web part and add a property to the exported file and re-import it (as explained in the thread above) or edit the page hosting the CQWP in SharePoint Designer to add a property to the tag directly: edit the page and while the CQWP is selected, switch to code view and add
UseCache=”False”
to the

Categories: CQWP Tags:

How To Set Focus To The First Field In An InfoPath Form Web Part

July 3rd, 2011 Abed Khooli No comments

InfoPath Form Web Parts seems to be slightly different. If you have a form in a web part, the focus upon page load is not anywhere in the form even if you have the tab index set in InfoPath Designer. The first logical answer may be to use JQuery for this simple housekeeping task. After all, you make the end users life a little easier. Unfortunately, JQuery (element.focus()) won’t work, not even for any other control on a page that has the InfoPath web part (JQuery does work in other scenarios and other web parts and forms). InfoPath forms have additional script handlers and that could be the issue.
As I faced this scenario recently, I decided to check the good old JavaScript with a timer, so setTimeout way the way out. Add a content editor web part to the page, edit its source and type the following:

Of course, you need to substitute your own ID for the text box you want to give the focus (view source or use Dev tools to get that). When done, click OK and in the CEWP settings, set Hidden to true (check the box) in Layout.
Your page with the web part form should now load with your favorite element having the focus and the cursor is ready there (this may take a little while, try a value less than 1000 but small values may not work).

How To Hide The Add Document Or Add New Item

June 29th, 2011 Abed Khooli 1 comment

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 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 ). Locate the line taht 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)

Categories: SharePoint Designer 2010, Views, Web Parts Tags: Hide Add Document

Custom Blog Rollup Using Content Query Web Part

June 27th, 2011 Abed Khooli 1 comment

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).
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 Body, Note
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 – around 67 lines). Of course, we need to name our style – I replaced the first line by

in that block (close to the end of the template). Here, I am taking the first 75 characters of the clean text and added a link to see the full post.
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.
Categories: CQWP Tags: blog rollup using CQWP

The SPXSLT Project And How To Turn Announcements Into Marquee

June 11th, 2011 Abed Khooli 3 comments

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.
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 and (several hundred lines) and delete it. You will use your own instead. You could use the one from Marc’s post as is, but here, we will do something different. The actual announcements view is rendered as table cells and we would like to make use of the liScroll Jquery plugin and turn our announcements linked titles into a news ticker or marquee.
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.
Categories: CEWP, DataView, Lists, SharePoint Designer 2010 Tags: , XSLT