Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to add an url to a table cell. I usually use the following, and it has never failed me until now.

 

TableCell c = new TableCell();

c.Controls.Add(new LiteralControl("<a href='" + 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 File_4.doc

 

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

 

Any suggestions?

Go Beavs!!!
Posted

HttpUtility.UrlEncode

 

If the filename contains the literal   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.Controls.Add(new LiteralControl("<a href='" + HttpUtility.UrlEncode(textURL) + "'>" + displayText + "</a>"));

 

The path myfolder/xxxLayout 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:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...