You can consider using one of the 2 solutions. One of which is to use Tag
property to assign an absolute file path and use it when clicked.
example code:
void CreateLink(string absoluteFilePath)
{
_linkPdfLabel_.Tag = absoluteFilePath;
_linkPdfLabel_.Text = Path.GetFileName(absoluteFilePath);
}
void linkPdfLabel__LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process process = new Process();
process.StartInfo.FileName = (string)linkPdfLabel_.Tag;
process.Start();
}
Another way is to use a property called Links
which is a LinkCollection
which holds a collection of Link
objects. You can use this to get the full link instead of the text.
example code:
void CreateFileLink(string absoluteFilePath)
{
linkPdfLabel_.Text = Path.GetFileName(absoluteFilePath);
var link = new LinkLabel.Link();
link.LinkData = absoluteFilePath;
linkPdfLabel_.Links.Add(link);
}
void linkPdfLabel__LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process process = new Process();
process.StartInfo.FileName = (string)linkPdfLabel_.Link[0].LinkData;
process.Start();
}