Results 1 to 7 of 7

Thread: [RESOLVED] GetManifestResourceStream & ResourceManager.GetStream

  1. #1

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Resolved [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:
    1. Dim myAssm As Assembly = Assembly.GetExecutingAssembly
    2. Dim myAssmName As String = myAssm.GetName.Name
    3. Dim resor1 As String = String.Concat(myAssmName, ".img.jpg")
    4. Dim resor2 As String = String.Concat(myAssmName, ".img")
    5. Dim resor3 As String = "img.jpg"
    6. Dim resor4 As String = "img"
    7.  
    8. Dim st As IO.Stream
    9. st = myAssm.GetManifestResourceStream(resor1)
    10. st = myAssm.GetManifestResourceStream(resor2)
    11. st = myAssm.GetManifestResourceStream(resor3)
    12. st = myAssm.GetManifestResourceStream(resor4)
    13.  
    14. st = My.Resources.ResourceManager.GetStream(resor1)
    15. st = My.Resources.ResourceManager.GetStream(resor2)
    16. st = My.Resources.ResourceManager.GetStream(resor3)
    17. st = My.Resources.ResourceManager.GetStream(resor4)

    What I'm missing here?

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim myImage As Image = My.Resources.MyImage
    Note that the property hase the same name as the file WITHOUT the extension.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    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...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: GetManifestResourceStream & ResourceManager.GetStream

    Quote Originally Posted by mickey_pt View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    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?

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: GetManifestResourceStream & ResourceManager.GetStream

    Quote Originally Posted by mickey_pt View Post
    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 View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: GetManifestResourceStream & ResourceManager.GetStream

    Quote Originally Posted by jmcilhinney View Post
    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...

    Thanks once again.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width