Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Passing filename from a hyperlink

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C - 25 Mar 2008 14:20 GMT
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
bruce barker - 25 Mar 2008 16:44 GMT
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)

> I have a DataGrid that displays file names from a directory and places them
> in a HyperLinkColumn as shown below.
[quoted text clipped - 11 lines]
>
> David
Anthony Jones - 25 Mar 2008 17:58 GMT
> > I have a DataGrid that displays file names from a directory and places them
> > in a HyperLinkColumn as shown below.
[quoted text clipped - 13 lines]
>
>    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()
)
}

Signature

Anthony Jones - MVP ASP/ASP.NET


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.