Link to home
Create AccountLog in
Avatar of n_srikanth4
n_srikanth4Flag for India

asked on

Escape Multiple Special Characters through query string URL


Question: How to  escape  multiple special characters ( -  ,  '  ,  &  ,  **  ,  ( , ) ,   / ,  \ ,  * , % , @ , # ) including leading and trailing spaces using Java Script .

I want to handle this using a Java Script mentioned here under(for a drill through report using the "Go to URL" option, "Action" Property  provided by SSRS 2008). Could you please correct my code below for atleast one of the Parameters posted below.

*********Note:  Please let me know how to use the CustomeCode if any  in the report expression , it is very Important, this is required

Java Script(used in the Report) :


="javascript:void(window.open('http://iisau182dev68.appdev.corptst.anz.com/ReportServer/Pages/ReportViewer.aspx?/ARMD/Trend_Analysis_Issues_Raised_by_Issue_Rating_Detail&rs:Command=Render&rc:Parameters=false&rc:HeaderArea=None&Start_Date="+Format(Parameters!Start_Date.Value,"dd/MM/yyyy")
+"&Division="+join(Parameters!Division.Value,"&Division=")
+"&Management_Awareness_Rating="+join(Parameters!Management_Awareness_Rating.Value,"&Management_Awareness_Rating=")
+"&Report_Rating="+join(Parameters!Report_Rating.Value,"&Report_Rating=")
+"&BU="+join(Parameters!BU.Value,"&BU=")
+"&End_Date="+Format(Parameters!End_Date.Value,"dd/MM/yyy")
+"&Division_Owned_And_Allocated="+Parameters!Division_Owned_And_Allocated.Value
+"&Audit_Manager="+Join(Parameters!Audit_Manager.Value, "&Audit_Manager=")
+"&Issue_Owner="+Join(Parameters!Issue_Owner.Value,"&Issue_Owner=")
+"&Issue_Rating="+Fields!Issue_Rating.Value
+"&Country="+join(Parameters!Country.Value,"&Country=")
+"&Region="+join(Parameters!Region.Value,"&Region=")
+"&Month_And_Year="+ FORMAT(Fields!ACTISSUEDATE.Value,"MMM-yy")+"','ChildW','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,scrollbars=yes'))"


Regards,

Sreekanth.
Avatar of hpierson
hpierson

JavaScript encodeURI() Function

http://www.w3schools.com/jsref/jsref_encodeuri.asp

I'm a little confused about your statement, it looks like you might need to escape some of your single and double quotes.

i.e. when you have a double quote nested within a double quote, you need to write

\"  

instead of just

"

for the inside double quote. Likewise for nested single quotes.
Avatar of Michel Plungjan
I am also confused. What does join do?

I would expect
"&Division="+join(Parameters!Division.Value,"&Division=")

to generate

"&Division=&Division=somevalue
Here is my suggestion
="javascript:var url='http://iisau182dev68.appdev.corptst.anz.com/ReportServer/Pages/ReportViewer.aspx?/ARMD/Trend_Analysis_Issues_Raised_by_Issue_Rating_Detail&rs:Command=Render&rc:Parameters=false&rc:HeaderArea=None&Start_Date="+Format(Parameters!Start_Date.Value,"dd/MM/yyyy")
+"&Division='+escape('"+Parameters!Division.Value+"')+"
+"&Management_Awareness_Rating='+escape('"+Parameters!Management_Awareness_Rating.Value+"')+"
+"&Report_Rating='+escape('"+Parameters!Report_Rating.Value+"')+"
+"&BU='+escape('"+Parameters!BU.Value+"')+"
+"&End_Date="+Format(Parameters!End_Date.Value,"dd/MM/yyy")
+"&Division_Owned_And_Allocated='+escape('"+Parameters!Division_Owned_And_Allocated.Value+"')+"
+"&Audit_Manager='+escape('"+Parameters!Audit_Manager.Value+"')+"
+"&Issue_Owner='+escape('"+Parameters!Issue_Owner.Value+"')+"
+"&Issue_Rating='+escape('"+Fields!Issue_Rating.Value+"')+"
+"&Country='+escape('"+Parameters!Country.Value+"')+"
+"&Region='+escape('"+Parameters!Region.Value+"')+"
+"&Month_And_Year="+ FORMAT(Fields!ACTISSUEDATE.Value,"MMM-yy")
+"','ChildW','toolbar,location,directories,status,menubar,resizable,scrollbars'))"

Open in new window

Avatar of n_srikanth4

ASKER

Hi mplungjan:

"Join"  is very much required as the Parameters are Multi Value Parameters  and should be used in the report expression. The expression I have posted is working , but i need write the escape sequence for the special characters. So can you rewrite the code above(with Escape) by putting "Join" and   send across it to me.

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi mplungian:

    I have added the web refernce , added the Custom Function and used the function in the Report Expression using the keyword "Code" as you have mentioned above.
    I am almost there . It's working for most of the special Characters excluding  the  Apstrophe ( ' )  and Ampersand (& )

Could you please provide me  the custom code so that it works for  even  Apstrophe ( ' )  and Ampersand (& ) .

I will really appreciate your reply .

Kind Regards,

Sreekanth.
Try changing System.Web.HttpUtility.UrlEncode to System.Uri.EscapeDataString
as reported here: Html and Uri String Encoding without System.Web
Hi mplungian:

 Thanks for the Immdiate reply.

    I have changed the code as per your guidelines and  added the below custom code .
    Do I have to remove the System.Web Refernce l ??.
    Secondly  the above link is in C# and the Custom code in SSRS can only be written in VB.  
   So,  Please correct the code below if it is wrong .

Public Function URLEncode (ByVal inURL As String) As String
Dim outURL As String
outURL = System.Uri.EscapeDataString(inURL).ToString
Return outURL
End Function


Regards,

Sreekanth.
I have no experience with either SSRS or C#
however since the SSRS worked with System.Web.HttpUtility.UrlEncode and that is accessible from C# I expected that System.Uri.EscapeDataString ALSO was accessible to SSRS

http://msdn.microsoft.com/en-us/library/system.uri.escapedatastring.aspx

More information here

http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx
good