skhurams
skhurams

Reputation: 2145

Path.Combine on urls gives exception : The given path's format is not supported

I have an error in following code

Uri imagesrc = new Uri("http://somewebsite.com/demo/images/slideshow/29.jpg");
Image image = Image.FromFile(Path.Combine("/comph/", imagesrc.ToString()));

I have also tried following code - where /comph/ is my root directory

Image.FromFile(Path.Combine("/comph/","http://some_other_website.com/demo/images/slideshow/29.jpg");

The above image URL is correct when I paste this URL in browser it shows the image.

With the above code an exception is raised:

The given path's format is not supported.

What is wrong with this code ?

Upvotes: 0

Views: 956

Answers (1)

Emond
Emond

Reputation: 50672

Path.Combine does not support urls.

You will have to translate the url to a (relative) file path first if you want to use Path.Combine

If you want to manipulate urls you can use the Url constructor that takes a base url and a relative url and combines them.

Upvotes: 3

Related Questions