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

asked on

URL Encoding in SSRS for Ampersand (&) and Apostrophe(')

Hi Experts:

    I have set the Assembly Refernce to "System.Web" , have written  the Custom Function "URLEncode" (using VB) and used the function in the Report Expression using the keyword "Code" as per the link below.

http://capstonebi.blogspot.com/2010/04/url-encoding-in-reporting-services.html 


 I am almost there . The code is  working for most of the special Characters excluding  the  Apstrophe ( ' )  and Ampersand (& )

Could you please provide me  the custom code (using VB ) or Correct the  code posted in the link above , so that it works for  even  Apstrophe ( ' )  and Ampersand (& )  as well.

I will really appreciate your reply .

Kind Regards,

Sreekanth.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

The code in the link is encoding the & as %26.
Also try the URLPathEncode function.
Avatar of n_srikanth4

ASKER

Hi CodeCruiser:

Can you please give me an example VB code to encode & and ' .

Regards,

Sreekanth.
As I said above, & is being encoded to %26. How else do you want to encode it?
ASKER CERTIFIED SOLUTION
Avatar of n_srikanth4
n_srikanth4
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
What URL do you have in inURL and what do you get in outURL?
Hi CodeCruiser :

Please See the code below (used in the Report Expression ) where I have used   "URLEncode"  VB function

="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="+Code.URLEncode(join(Parameters!Division.Value,"&Division="))
+"&Management_Awareness_Rating="+Code.URLEncode(join(Parameters!Management_Awareness_Rating.Value,"&Management_Awareness_Rating="))
+"&Report_Rating="+Code.URLEncode(join(Parameters!Report_Rating.Value,"&Report_Rating="))
+"&BU="+Code.URLEncode(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="+Code.URLEncode(Join(Parameters!Audit_Manager.Value, "&Audit_Manager="))
+"&Issue_Owner="+Code.URLEncode(Join(Parameters!Issue_Owner.Value,"&Issue_Owner="))
+"&Issue_Rating="+Fields!Issue_Rating.Value
+"&Country="+Code.URLEncode(join(Parameters!Country.Value,"&Country="))
+"&Region="+Code.URLEncode(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'))"


Note : Here I am  passing Multi Value parameters where I am using the function  “Join” and it works absolutely fine for all the special characters excluding Ampersand and Apostrophe.

Question :  How to encode the  Ampersand(&) and Apostrophe (‘) and pass through the query string URL where I need to escape these characters.


I appreciate your Immediate reply.


Regards,

Sreekanth.


   
Hi CodeCruiser:

No it doesn't work for me ..  I need a custom function , encodes the  Ampersand(&) and Apostrophe (‘) and pass through the query string URL (like '&'  is encoded as %26 ) and  escape these characters while passing through the query string.

Could you please resolve this query . I appreciate your immediate reply.

Regards,

Sreekanth.

The trouble is that & is encoded by the EncodeURL but the apostrophe is probably not so its problamatic with SQL Server. One way could be

Public Function UrlPathEncode (ByVal inURL As String) As String
Dim outURL As String
outURL = System.Web.HttpUtility.UrlPathEncode(inURL).ToString
Return outURL.Replace("'", "''")
End Function
good