HyperLink for files with spaces in the path not working in Internet Explorer.

I was using asp:hyperlink  control to show links to local LAN files , e.g.

<asp:HyperLink ID=”lnkToClick” runat=”server”>link to LAN fileasp:HyperLink>

 Me.lnkToClick.NavigateUrl = file://\ServerFolderFileName.ext

 It worked fine, unless Folder path or filename has spaces in it(Probably other special character could cause the same problem). In this case, generated html file has %20 instead of space and clicking on the generated link in IE doesn’t open file.
In othe words Internet Explorer 6. doesn’t open the following link
        file://\databasedocssallystaff’ _fcksavedurl=’file://\ServerFolderTWO%20WORDS.doc”>file://\databasedocssallystaff’>file://\ServerFolderTWO%20WORDS.doc”>file://\ServerFolderTWO WORDS.doc

After some investigation with Reflector I found that HyperLink calls AddAttributesToRender, which calls  ResolveClientUrl, which in turn calls  HttpUtility.UrlPathEncode. And there is no simple way to exclude encoding for “file://“ paths.
There is ASP.NET 2.0  asp:hyperlink  control bug, the control worked correctly in ASP.NET 1.1 .

However ther is a simple alternative -use A control instead of HyperLink.

<a ID=”lnkToClick” runat=”server”>link to LAN file</a>


 Me.lnkToClick.href = file://\ServerFolderFileName.ext

The similar problem is reported to MS here.

One reader of the post asked how to replace  
<asp:HyperLink runat=”server” Target=”_blank” Text=”<img src=pdficon_small.gif border=0 align=absmiddle alt=’Load PDF File’>” NavigateUrl='<%# DataBinder.Eval(Container, “DataItem.FilePath”) %>’>

My suggestion was:

<a runat=”server” target=”_blank”  href='<%# DataBinder.Eval(Container, “DataItem.FilePath”) %>’>
<img src=pdficon_small.gif border=0 align=absmiddle alt=’Load PDF File’>