Reputation: 1718
I have a silverlight 5 project called Kinemat.AuthoringTool. Inside this project i have a folder called Backgrounds and there i have some images (their Build Action is Content
). I want to access an image's stream and then upload that image on a server. After some research on msdn i use the following code:
StreamResourceInfo streamResourceInfo =
Application.GetResourceStream(new Uri("PathToPutHere"));
Stream imageStream = streamResourceInfo.Stream;
of course using the path "/Backgrounds/imageName" does not work. What is the correct path then?
Upvotes: 3
Views: 93
Reputation: 31721
Instead, make the images with the build property of Embeded
and path to it via namespace and name in the containing dll. I have created such an image extractor for a stream (Can be used outside of Silverlight)
public static Stream GetImage(string resourceName)
{
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null)
throw new ArgumentException(
$"No resource with name {resourceName} in {assembly.FullName}");
return stream;
}
Upvotes: 1