How to get kml stream from local machine
I just can't get the streamResource to get a file from my computer. At first i tried the
Application.GetResourceStream
But found that i have to use the
Application.GetRemoteStream
So i tried:
Uri uriAdress = new Uri("file:///c:/mapsource/wildlife.kml", UriKind.RelativeOrAbsolute);
StreamResourceInfo streamResource = Application.GetRemoteStream(uriAdress);
But got an exception telling me that the GetRemoteStream expects a relative URI or a pack;//siteoforigin:
I searched around 开发者_开发知识库and found that this should be really simple, so my final attempt was:
Uri uriAdress = new Uri("pack://siteoforigin:c:/mapsource/wildlife.kml", UriKind.RelativeOrAbsolute);
StreamResourceInfo streamResource = Application.GetRemoteStream(uriAdress);
I got that the URI localpath was ""/mapsource/wildlife.kml", which is wrong, and i got the exception from the StreamResourceInfo:
"Unsupported URI syntax. Method expects a relative URI or a pack://siteoforigin:,,,/ form of absolute URI"
Anyone got an idea of what i'm doing wrong?
Thanks in advance
Application.GetResourceStream
is for files that are within the app.
Application.GetRemoteStream
is for files located on the server where the app was deployed.
Why not use FileStream?
FileStream stream = File.Open("c:/mapsource/wildlife.kml", FileMode.Open, FileAccess.READ))
精彩评论