0

I have a TextBox where I can send data to some RichTextBox. When I type something like file:///FilePath1/FilePath2/FileName3.txt, send to RichTextBox and click on the link (LinkClicked Event) it works and I can open the file but if some FilePath has spaces (for exemple file:///File Path1/FilePath 2/FileName3.txt) it doesn't works.

I tryed

string myString = myString.FileName;
myString = myString.Replace(" ", "%20");  // '%20' not accepted because it 
                                          //                changes the FileName

and

Uri myLink = new Uri(myString );

but it's still not working. Any sugestion?

mafap
  • 371
  • 3
  • 18
  • 40
  • 1
    possible duplicate of [Link to file path with space in Richtextbox](http://stackoverflow.com/questions/17719021/link-to-file-path-with-space-in-richtextbox) – Chris Sep 18 '13 at 21:34
  • 1
    this is not easy at all, there is a custom RichTextBox which allows you to display link with arbitrary text in `codeproject` at here http://www.codeproject.com/Articles/9196/Links-with-arbitrary-text-in-a-RichTextBox – King King Sep 18 '13 at 21:37
  • @Chris the issue is the same but none of the answers worked for me – mafap Sep 18 '13 at 21:43
  • tried [Url Encode](http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx)? – Omri Btian Sep 18 '13 at 21:47
  • @Omribitan `var myLink = Uri.EscapeDataString(myString );` didn't work – mafap Sep 18 '13 at 22:02
  • @mafap you don't know how to modify the code to make it work for you. – King King Sep 18 '13 at 22:06
  • @KingKing I was refering to the possible duplicate answers. I had seen this article in codeproject already, I was just looking for another way to do that. – mafap Sep 18 '13 at 22:18
  • sorry @KingKing can you explain how to use the solution shown in the article/duplicate question? It gives me some errors in `InsertLink` and other funtions. – mafap Sep 18 '13 at 22:55
  • @KingKing I imported the .DLL but it doesn't work :/ – mafap Sep 19 '13 at 13:10
  • 1
    @mafap I've made a demo for you at here http://www.mediafire.com/?ts7l8jdnuhehi07 **It's very simple**. The point is the `e.LinkText` got in `LinkClicked` event handler contains both `actual link text` and `link url` separated by the character **#** – King King Sep 19 '13 at 13:36
  • @KingKing Thanks for your help and time but I solved this using `myString = myString.Replace(" ", "%20");` and in `LinkClicked` event using a try-catch statement where catch calls a new Process to open my file. – mafap Sep 19 '13 at 17:12

0 Answers0