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://\\Server\Folder\FileName.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://\\database\docs\sally\staff' _fcksavedurl='file://\\Server\Folder\TWO%20WORDS.doc">file://\\database\docs\sally\staff'>file://\\Server\Folder\TWO%20WORDS.doc">file://\\Server\Folder\TWO 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://\\Server\Folder\FileName.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") %>'>
</asp:HyperLink>

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'>
</a>

posted @ Friday, July 14, 2006 11:16 AM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 1 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910