[RESOLVED] GetManifestResourceStream & ResourceManager.GetStream
Hello
I have an application that has some files in the resources that i need to extract at run-time, but i can't find a way to do this...
Neither the Assembly.GetManifestResourceStream neither the My.Resources.ResourceManager.GetStream work.
I already tried in various forms to pass the string name of the resource:
- AssemblyName.Resource.Ext
- AssemblyName.Resource
- Resource.Ext
- Resource
And none of them work. I created a simple app to test this and added a little img.jpg:
The code:
vb.net Code:
Dim myAssm As Assembly = Assembly.GetExecutingAssembly
Dim myAssmName As String = myAssm.GetName.Name
Dim resor1 As String = String.Concat(myAssmName, ".img.jpg")
Dim resor2 As String = String.Concat(myAssmName, ".img")
Dim resor3 As String = "img.jpg"
Dim resor4 As String = "img"
Dim st As IO.Stream
st = myAssm.GetManifestResourceStream(resor1)
st = myAssm.GetManifestResourceStream(resor2)
st = myAssm.GetManifestResourceStream(resor3)
st = myAssm.GetManifestResourceStream(resor4)
st = My.Resources.ResourceManager.GetStream(resor1)
st = My.Resources.ResourceManager.GetStream(resor2)
st = My.Resources.ResourceManager.GetStream(resor3)
st = My.Resources.ResourceManager.GetStream(resor4)
What I'm missing here?
Re: GetManifestResourceStream & ResourceManager.GetStream
How exactly did you add the resources in the first place? The simplest option is to NOT add them to the solution at all, but simply add them to the Resources page of the project properties. If you add an image file named "MyImage.jpg" then you would access the resource like so:
vb.net Code:
Dim myImage As Image = My.Resources.MyImage
Note that the property hase the same name as the file WITHOUT the extension.
Re: GetManifestResourceStream & ResourceManager.GetStream
Just used the resources tab and added new resource.
Yes i know that, but in this particular case i need the resources, and "extract" some of them to the hd...
Re: GetManifestResourceStream & ResourceManager.GetStream
Quote:
Originally Posted by
mickey_pt
Just used the resources tab and added new resource.
Yes i know that, but in this particular case i need the resources, and "extract" some of them to the hd...
I showed you how to create an Image object. An Image object has a Save method.
Re: GetManifestResourceStream & ResourceManager.GetStream
The image file was only a sample, i have other file types, like i wrote in the beginning of the thread...
But forgetting the file type, the GetManifestResourceStream and the ResourceManager.GetStream doesn't work why?
Re: GetManifestResourceStream & ResourceManager.GetStream
Quote:
Originally Posted by
mickey_pt
The image file was only a sample, i have other file types, like i wrote in the beginning of the thread...
So? It doesn;t matter what type of data you have. All data can be saved to a file one way or another. Just write the appropriate code for each type of resource.
Quote:
Originally Posted by
mickey_pt
But forgetting the file type, the GetManifestResourceStream and the ResourceManager.GetStream doesn't work why?
Because that is for resources that you have added via the Solution Explorer, not for those you access via My.Resources.
Re: GetManifestResourceStream & ResourceManager.GetStream
Quote:
Originally Posted by
jmcilhinney
So? It doesn;t matter what type of data you have. All data can be saved to a file one way or another. Just write the appropriate code for each type of resource.Because that is for resources that you have added via the Solution Explorer, not for those you access via My.Resources.
So that was the problem, i assumed that the resources could be the ones in the resources of the application... :o
Thanks once again.