Gauri K.
Gauri K.

Reputation: 79

How to get filepath with Uri without "file:///"

I get an image path with Uri, which is used as the source path in a report. This image is also loaded in an imagebox. The problem is that Uri adds "file:///" to the path. Therefore the image cannot be displayed on the report. How can I get the image path without that portion?

Upvotes: 1

Views: 618

Answers (2)

brunnerh
brunnerh

Reputation: 185290

Use Uri.LocalPath:

Gets a local operating-system representation of a file name.

Just tested this in fsi:

> let u = new Uri("file:///C:/Users/Public/Test.png");;

val u : Uri = file:///C:/Users/Public/Test.png

> u.LocalPath;;

val it : string = "C:\Users\Public\Test.png"

Looks good.

Upvotes: 4

Rafal
Rafal

Reputation: 1091

If you just want to remove "file:///" from Uri try:

string uriPath =... //your path with "file:///" 

string path = uriPath.Replace("file:///", "");

Upvotes: 0

Related Questions