If Filename Has Single Quote C# Javascript Does Not Get Executed
I need to pass a URL from C# to javascript. The problem is if the filename has single quote, it does not execute the javascript. When I use HttpUtility.HtmlEncode(fileNameWithoutEx
Solution 1:
Use Uri.EscapeDataString(yourLinkHere);. See Uri.EscapeDataString on MSDN.
Solution 2:
You're embedding the title and URL within quote-delimited strings in JavaScript, so you need to escape them.
title = title.Replace("'","\\'");url = url.Replace("'","\\'");Solution 3:
You can try percent codes. I would recommned using %20 in the place of spaces as well. You can chance the file name itself or the way you route to it in code.
urlstring.replace("'", "%27")
Try to replace your ' with %27 which is the standard percent encode for '
Characters with reserved purposes should be replaced to guarantee functionality in all environments. You can view the list and read up on this here.
Post a Comment for "If Filename Has Single Quote C# Javascript Does Not Get Executed"