tags:

views:

92

answers:

3

I have the following string:

string text = @"<a href=""http://raustdsx0700.real.local:7782/analytics/saw.dll?PortalPages&amp;PortalPath=" + dashboardURL + "&Page=" + reportName + @"&P0=1&P1=eq&P2=Project.""Project Name"" target=""_blank"">" + reportName + "</a><br/><br/>";

When this string gets written to my page, it looks like this:

<a href="http://raustdsx0700.real.local:7782/analytics/saw.dll?PortalPages&amp;PortalPath=/shared/Real Estate Reporting_portal/REGIS:  Financial Reporting UAT/&Page=DR - 3: Debt Payment History&P0=1&P1=eq&P2=Project\."Project Name" target="_blank">DR - 3: Debt Payment History</a>

Can someone help explain why the period id being escaped? I'm fumbling with how to escape this properly.

Thanks.

+1  A: 

I'm not sure exactly what your output should look like but String.Format and escaping are your friend.

string text = String.Format("<a href='http://raustdsx0700.real.local:7782/analytics/saw.dll?PortalPages&amp;PortalPath={0}&amp;Page={1}&amp;P0=1&amp;P1=eq&amp;P2=Project.\"Project Name\"'' target='_blank'>{1}</a><br/><br/>",dashboardURL,reportName); 
Richard Friend
+1  A: 

If you are intent on using quotes in your URL, then use single-quotes for your tag attributes.

string text = "<a href='http://raustdsx0700.real.local:7782/analytics/saw.dll?PortalPages&amp;PortalPath=" + dashboardURL + "&Page=" + reportName + "&P0=1&P1=eq&P2=Project.\"Project Name\"' target='_blank'>" + reportName + "</a><br/><br/>";

Or better, url-escape the quote (%22):

string text = "<a href='http://raustdsx0700.real.local:7782/analytics/saw.dll?PortalPages&amp;PortalPath=" + dashboardURL + "&Page=" + reportName + "&P0=1&P1=eq&P2=Project.%22Project Name%22' target='_blank'>" + reportName + "</a><br/><br/>";
Greg
+1  A: 

You need to urlencode your string, check this out: http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

Lukasz Dziedzia