Add URL to Table

kcwallace

Well-known member
Joined
May 27, 2004
Messages
172
Location
Irvine, CA
I need to add an url to a table cell. I usually use the following, and it has never failed me until now.

C#:
TableCell c = new TableCell();

c.Controls.Add(new LiteralControl("" + textURL + ">" + displayText + "</a>"));

Our application allows users to upload a file, and then we store the path in the database.

I have found that they store several files as the following:

myfolder/xxxLayout&nbsp;File_4.doc

Unfortunately, IE translates the "nbsp;" into a space, and therefore cannot find the file.

Any suggestions?
 
HttpUtility.UrlEncode

If the filename contains the literal &nbsp; then all you should need to do is URL-encode the filename before using it. The HttpUtility class has a method to do this:

C#:
c.Controls.Add(new LiteralControl("" + HttpUtility.UrlEncode(textURL) + ">" + displayText + "</a>"));

The path myfolder/xxxLayout&nbsp;File_4.doc should then be output as myfolder%2fxxxLayout%26nbsp%3bFile_4.doc.

Another approach would be to stop using the LiteralControl class and instead use the HtmlAnchor class. This should handle the encoding of the URL correctly, without the need for HttpUtility.UrlEncode.

Either way this should give you some idea of what to do.

Good luck :cool:
 
Back
Top