Passing filename from a hyperlink

  • Thread starter Thread starter David C
  • Start date Start date
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
 
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)
 
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()
)
}
 
Back
Top