How to create a file link in RichTextBox ?

K

ksskumar

Hi Friends,

I am creating a application using C#. In that application I am using
RichTextBox (System.Windows.Forms.RichTextBox).

My query is how to create a file link in Rich text box. Means, I want
to embed file in Richtextbox. If the user click / doubleclick /
Ctrl+click the link, that file should open. It is like hyperlink in
HTML.

The suggestion can be in C# or VB.NET.

Thanks in advance,

Kumar
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (ksskumar) scripsit:
I am creating a application using C#. In that application I am using
RichTextBox (System.Windows.Forms.RichTextBox).

My query is how to create a file link in Rich text box. Means, I want
to embed file in Richtextbox. If the user click / doubleclick /
Ctrl+click the link, that file should open. It is like hyperlink in
HTML.

Did you have a look at the RTF specification?

<http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec.asp>

SCNR
 
K

kumar kss

Hi Champika Nirosh ,

Thanks for your valid suggestion. It is working fine with your idea.

But, I have one more doubt, I gave the commend to create the link like
this,

rtbTest.Text = @"file:/c:\Test.mdb";

in the output along with the file name "file:/" also display as a link.
So I have to remove it before use the LinkText to the process.

Is there any way to display the file name alone as a link?

Thanks in advance,

Kumar
 
H

Herfried K. Wagner [MVP]

* kumar kss said:
Thanks for your valid suggestion. It is working fine with your idea.

But, I have one more doubt, I gave the commend to create the link like
this,

rtbTest.Text = @"file:/c:\Test.mdb";

in the output along with the file name "file:/" also display as a link.
So I have to remove it before use the LinkText to the process.

Is there any way to display the file name alone as a link?

Add a LinkLabel control to your form, then add this code:

\\\
Me.LinkLabel1.Text = "Besuchen Sie mich in Berlin oder Hamburg!"
Me.LinkLabel1.Links.Add(21, 6, "http://www.berlin.de")
Me.LinkLabel1.Links.Add(33, 7, "http://www.hamburg.de")
..
..
..
Private Sub LinkLabel1_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Process.Start(e.Link.LinkData)
End Sub
///

You can try to get the filename using 'System.IO.Path.GetFileName'.
 
K

kumar kss

Hi Herfried K. Wagner,

Thank you very much for the suggestion.

But, I am working in RTB (RichTextBox) not in LinkLabel. I want to
create a link in RichTextBox. That too part of the text.

My code fragment is something like this,

rtbTest.Text = "Click this link to open file " + @"file:/c:\Test.mdb";

output gives the link. but as I told above, along with the file name
"file:/" is also shown in the link.

If any possibility to avoid this ?

Herfried, still you have doubt, please let me know.

Thanks in advance,
Kumar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top