Passing filename from a hyperlink

D

David C

I have a DataGrid that displays file names from a directory and places them
in a HyperLinkColumn as shown below.

<asp:HyperLinkColumn DataNavigateUrlField="Name"
DataTextField="Name" HeaderText="File Name"
DataNavigateUrlFormatString="ShowDocs.aspx?doc={0}"
Target="_blank" />


My problem is that if the filename contains the character "&" then I have a
problem reading it from the QueryString in the page I am linking to. It
only reads the QueryString named "doc" up to the &. I assume I will have the
same problem if there is a ? in the filename. Does anyone know how I can
handle this better? The process works great for most file names. Thank you.

David
 
B

bruce barker

all args to a query string should be url encoded. see:

HttpUtility.UrlEncode

note: they are automatically decoded when loaded into the query string
collection.

-- bruce (sqlwork.com)
 
A

Anthony Jones

bruce barker said:
all args to a query string should be url encoded. see:

HttpUtility.UrlEncode

And the two ways to do that are:-

Add another field to the datasource that has the file name Url Encoded

OR

Add a class that inherits from HyperLinkColumn and override the
FormatDataNavigateUrlValue method:-

//C#
protect virtual string FormatDataNaviageUrlValue(Object dataUrlValue)
{

base.FormatDataNaviageUrlValue(HttpUtility.UrlEncode(dataUrlValue.ToString()
)
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top