I have an XmlTextReader to read series of XML files to load some information in to my program.
However, in some XML files I have the file name of an image and I want to load that image.
But the problem is the XML file does not have the full path of the image.
<Image id="ImageId" File="Image.bmp" />
<!-- full path is not available. Image is behind XML-->
This means the Image exist where the xml file exists.
for some reason, the only way to get the path of the XML file is to get the path of the XmlTextReader reading the current XML file.
I did some research and I found out you can retrieve the XML path from the XmlTextReader as below:
string path = reader.BaseURI; // this will get the path of reading XML
// reader is XmlTextReader
How can I combine path
with the image's path?
I have tried the following way:
string FullImagePath = Path.Combine(reader.BaseURI, imagePath);
These are the values of the variables:
reader.BaseURI
is"file:///D:/.../currentXml.xml"
imagePath
is"Image.bmp"
.- Finally,
FullImagePath
, after assigning the result ofPath.Combine
isfile:///D:/.../currentXml.xml\\Image.bmp
, which is not what I expect.
Expected path of the image is: D:/.../Image.bmp
, in the same directory as currentXml.xml
.
So how can I get the path of the image file?