Samy Sammour
Samy Sammour

Reputation: 2465

Hyperlink to file in the same folder, EPPlus C#

I am using EPPlus library in c#. I am trying to add a hyperlink in an Excel file that leads to a file in the current path. but I cannot write the full path because it is a downloadable folder. that means it depends on the location of the folder in the client.

I used this code:

using (ExcelRange rng = ws.Cells[i, 1])
{
    rng.Hyperlink = new Uri("file://.\\sss.jpg");
    rng.Value = p.Name;
}

But I am receiving an error from the Uri line:

Not a valid Uri

Anybody has an Idea how can I write a link to a file in the same folder?

Thank you!

Upvotes: 1

Views: 1140

Answers (1)

Mark Pattison
Mark Pattison

Reputation: 3029

Try this:

using (ExcelRange rng = ws.Cells[i, 1])
{
    rng.Hyperlink = new Uri("sss.jpg", UriKind.Relative);
    rng.Value = p.Name;
}

This creates a relative URI. I've tested this with EPPlus and it indeed looks for the file relative to the location of the Excel workbook.

Upvotes: 1

Related Questions