Showing posts with label URL. Show all posts
Showing posts with label URL. Show all posts

Monday, 7 December 2015

SSRS Open Linked Report In New Window with Javascript

I recently wanted to set op a series of interlinked reports using SQL Server Reporting Services (SSRS) targetting a 2012 instance. I used javascript in a "Custom URL" action on a field to create the link.  Everything looked OK, but further testing I noticed the following type of error was often being generated in in the drill through report:

The report execution xnf441454bs2oh45hqvrkd45 has expired or cannot be found. (rsExecutionNotFound)


The problem was the parameter:  I was using a text field to pass through information for the parameter, and this textual information could include an Ampersand (&).

This is obviously a reserved character, so requires escaping.

To do this, we must utilise SSRS's commands REPLACE and ESCAPE in the custom action.  The easiest way to explain this is in this example:

="javascript:void window.open('" & Globals!ReportServerUrl & "/ReportServer/Pages/ReportViewer.aspx?%2fPhonebook+Reports%2fDepartment&department="
+Replace(Fields!Team.Value,"&","' + escape('&') + '") & "&location="+Replace(Fields!Location.Value,"&","' + escape('&') + '")
 & "&rs:Command=Render=','_blank','')"

Using this format to build the link, I can now open "drill through" reports with a parameter that contains an ampersand, and no longer get the "report execution" error above.   Nice.

Festina Limited Edition Chrono Bike 2015 Men’s Quartz Watch with Brown Dial F16883/1

Click here for a list of the best selling Festina watches this week.

Wednesday, 6 January 2010

What is the difference between a URI and a URL?

If you get confused between URLs (Uniform Resource Locators) and URIs (Uniform Resource Identifiers), then simply think of a URL as a special type of URI used to point to resources on the WWW.

The term "URL" is now deprecated (a term meaning marked for removal in computing circles), and the term "URI" is now the accepted term in computer science. However with the rise of the internet "URL" has become entrenched within the English language and is used and understood widely among non computer scientists. It's not possible for any group of individuals to deprecate words (although plenty have tried...) so "URL" will probably long outlive its technical definition.

At the end of the day, I expect that if you should use the term "URL" when you really mean "URI" everybody will know what you mean!

Tuesday, 5 January 2010

Strip and manipulate a URL by breaking it into segments (.NET 2.0)

I recently required a method that would take a string that contain a URL (href), and another string that contained a root section of this URL (root), and return a string that contained the remained of the URL (i.e. the section of href that remained once the root had been removed).

To make matters more complicated, the href parameter could have some unusual features.  Because this URL was pointing to content created by users in a Content Management System (CMS), some segments of the URL contained trailing or leading white space (segments being the bits of the URL between the slashes).   This whitespace is fine in the CMS system, but my method must strip this whitespace to return a canonical URL.

Fortunately .Net 2.0 onwards provides us with the URI class.  This has lots of fabulous methods and properties, but in this example I shall use it to:
  1. turn the parameter strings "root" and "href" URLs into canonical URIs
  2. break down the "href" parameter into segments, 
  3. ignore the segments that exist in the "root" parameter,
  4. strip leading and trailing whitespace from the remaining segments
  5. return the canonicalised section of the URL


string GetRootStrippedURI(string root, string href)
{
    Uri fileUri = new Uri(Uri.UnescapeDataString(href));
    Uri rootUri = new Uri(Uri.UnescapeDataString(root));

    // Create the return string from the root
    string strippedExtension = "";

    // Loop through segments not in the root and clean them up
    for (int i = rootUri.Segments.Length; i < fileUri.Segments.Length - 1; i++)
    {
        strippedExtension += fileUri.Segments[i].TrimEnd().TrimStart();
    }
    return strippedExtension;      
}