Showing posts with label #SPC09. Show all posts
Showing posts with label #SPC09. Show all posts

Thursday, June 17, 2010

CQWP Expiration Date issue

Scenario
  • You would like to filter your Content Query Web Part by Expiration Date.  You would like items to show up when any of the following are true (OR filter)

    • They are not expired (Expiration is greater than or equal to [Today])
    • Have no expiration date (expiration is null)
Issue
  • There is no Null option in the CQWP Web Part Edit Toolpane, therefore you can only enter the first criteria above.  Therefore, when the Expiration field is left blank (null date), the value is excluded from results.
Resolution
  • One workaround is to use a Data View web part via SharePoint Designer instead of the CQWP.  This will allow you to display a similar format, while adding a null date to the filter.

    • Use the a href="/{@FileDirRef}/DispForm.aspx?ID={@ID}" syntax to include a hyperlink in the title
    • The ... (more) feature will not be included

Thursday, May 20, 2010

Tuesday, December 8, 2009

My Links SharePoint list web part mods using HtmlFilter

Goal
  • Modify the standard Links List web part properties using HtmlFilter as follows

    • Remove column header
    • Clear empty group by selector
    • Offer open link in new window option

Solution
  • Add an OpenInNewWindow yes/no column to the Links List
  • Add a Group column to the Links List

    • This can be any type that supports Grouping

  • Add an OpenInNewWindowReplace calculated column to the Links list

    • Calculation:   =OpenInNewWindow&"OpenInNewWindowReplace"

  • Create a view 

    • Group on the Group column
    • Groups should be Expanded
    • Include the OpenInNewWindowReplace calculated column

  • Add the default Links List web part to a page on the site

    • Set the web part view to the newly created view from the previous step
    • Append the following to the Web Part description (under advanced)

      • RemoveColumnHeadersAndBlankGroup


  • Add the following HtmlFilters to the page, masterpage, or to a SmartPart on the page (VB.Net syntax).  For C#, change the "" to \"  and ' to // and don't forget your ;'s
'Remove Blank Grouping from Web Parts with "RemoveColumnHeadersAndBlankGroup" at the end of the Web Part description. Updated to ignore expanded group, due to ajax population resulting in hiding the entire section.
FilterReplaceValues.Add("(?is:(?<first>RemoveColumnHeadersAndBlankGroup""(.(?!class=""ms-gb""))*?titl(?<title>\d+)-1_"")(?<second>(.(?!MSOZoneCell_WebPart))*?Group</a> :&nbsp; <span(.(?!TBODY id=""foot))+?isLoaded=""true""))", "${first} style=""display:none"" ${second}")
'Remove Column Headers from Web Parts with "RemoveColumnHeadersAndBlankGroup" at the end of the Web Part description
FilterReplaceValues.Add("(?is:RemoveColumnHeadersAndBlankGroup(?<first>"".*?<TR class=""ms-viewheadertr""))", "${first} style=""display:none""")

'Links with preceding "TRUEOpenInNewWindowReplace" calculated column values should open in a new window
'Hide the OpenInNewWindowReplace Calculated Column Header
FilterReplaceValues.Add("(?is:<TH (?<first>(.(?!</TH>))*?OpenInNewWindowReplace.*?</TH>))", "<TH style=""display:none"" ${first}")
'TRUE (yes)
FilterReplaceValues.Add("(?is:<TD (?<first>(.(?!</TD>))*?"">TRUEOpenInNewWindowReplace</TD>.*?<A .*?) HREF)", "<TD style=""display:none"" ${first} target=""_blank"" HREF")
'FALSE (no) or nothing (blank)
FilterReplaceValues.Add("(?is:<TD (?<first>(.(?!</TD>))*?"">(FALSE)?OpenInNewWindowReplace</TD>))", "<TD style=""display:none"" ${first}")

Friday, November 20, 2009

HtmlFilter - The ultimate SharePoint and .Net code hack

If you've ever run into a wall of closed classes or inaccessible functionality within asp.net or SharePoint, then I have good news for you. When you can't interface with out of the box server side objects, you can always fall back on the HtmlFilter to save you.

The code I wrote will allow you to intercept whatever HTML the server outputs to the browser and filter it via REGEX expressions returning whatever you would like. It works via the page.response.filter property.

You can add the filter at any point (before pre-render) in your server-side code.  This allows you to selectively apply filters based on server side code and to insert server-side parameters.
Warning: Regular Expressions will increase the server processor load.  Each page request implementng this tool will add some overhead as it searches the html.  You may need to load test your expressions and possibly optimize them.  Note that there is also a property that will bypass the filter on asynchronous page loads, although the performance hit of an asynchronous page load will already be reduced since only the updated html will be filtered.  On the other hand, the overhead on the server will probably be less than the overhead that would be created on the client and via increased content bandwidth if a javascript solution was used.

The HtmlFilter is now available on CodePlex.
Refer to the CodePlex project for future updates and usage examples.

Setup
  • Add the HtmlFilter.vb file to the App_Code\VBCode folder

    • See here for how to configure separate VBCode and CSCode folders using CodeSubdirectories in the web.config

Usage
  • In your UserControl or Page CodeBehind, add the following code in the Page_Load event handler

    • For VB

      Dim FilterReplaceValues As New Specialized.NameValueCollection
      FilterReplaceValues.Add("Your Regex Expression", "Your Replacement Expression")
      HtmlFilter.SetHtmlFilter(Page, FilterReplaceValues, 10000)
      

    • For C#

      Specialized.NameValueCollection FilterReplaceValues = new Specialized.NameValueCollection();
      FilterReplaceValues.Add("Your Regex Expression", "Your Replacement Expression");
      HtmlFilter.SetHtmlFilter(Page, FilterReplaceValues, 10000);


  • The number 10000 in the code above should be at least the length of any replaceable string.

    • This is used in the stream to reduce buffer size.
    • Example:  If you will be replacing strings up to 20 characters, you would put 20 or more there.

  • Fill in the appropriate Regex and Replacement expressions according to your needs.

    • You may add multiple FilterReplaceValues to the collection.  It will parse each one in order.
    • Examples (VB)

      • Remove all UserControl prepended Identifier strings from Form elements, for use in a custom cross-page post scenario.

        "(name|id)=""[^""]*" & Me.ID & "[\$_]", "$1="""

      • SharePoint: Remove the Edit and Export Web Part Edit items from the Edit Menu

        "(?s:<ie:menuitem type=""separator"" /><ie:menuitem title(?!.*separator.*id=""MSOMenu_Edit"").*MSOMenu_Edit.*Export\.\.\.(\r|\n|\s)*</ie:menuitem>)", ""



  • For help creating your own expressions, use some of these tools