Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading text file from Resources

Reading text file from Resources

Scheduled Pinned Locked Moved C#
data-structuresquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muntyness
    wrote on last edited by
    #1

    So I have a text file in my projects resources that I need to read into an array. It's path is: global::Project1.Properties.Resources.rar it returns byte[] How would I get information from this file? - Munty

    J 1 Reply Last reply
    0
    • M Muntyness

      So I have a text file in my projects resources that I need to read into an array. It's path is: global::Project1.Properties.Resources.rar it returns byte[] How would I get information from this file? - Munty

      J Offline
      J Offline
      JoeSharp
      wrote on last edited by
      #2

      Hi try this using (Stream s = this.GetType().Assembly.GetManifestResourceStream("Project1.Properties.Resources.rar")) { // Read the content into byte array. }

      M 1 Reply Last reply
      0
      • J JoeSharp

        Hi try this using (Stream s = this.GetType().Assembly.GetManifestResourceStream("Project1.Properties.Resources.rar")) { // Read the content into byte array. }

        M Offline
        M Offline
        Muntyness
        wrote on last edited by
        #3

        Hi, Thanks for replying. this.GetType().Assembly.GetManifestResourceStream("string") keeps on returning null. Doesnt matter what I use it with, even files that I successfully use elsewhere will always return a null :/ Here are one of the tests that returned a null: Object o = this.GetType().Assembly.GetManifestResourceStream("Project1.Properties.Resources._01") This shouldnt have returned a null because I've used that resource elsewhere for an image. Here is the code I used that resource for that worked: imagePanel[0] = Project1.Properties.Resources._01; - Munty

        J 1 Reply Last reply
        0
        • M Muntyness

          Hi, Thanks for replying. this.GetType().Assembly.GetManifestResourceStream("string") keeps on returning null. Doesnt matter what I use it with, even files that I successfully use elsewhere will always return a null :/ Here are one of the tests that returned a null: Object o = this.GetType().Assembly.GetManifestResourceStream("Project1.Properties.Resources._01") This shouldnt have returned a null because I've used that resource elsewhere for an image. Here is the code I used that resource for that worked: imagePanel[0] = Project1.Properties.Resources._01; - Munty

          J Offline
          J Offline
          JoeSharp
          wrote on last edited by
          #4

          hi munty have you set the build action property of the file to Embedded Resource?

          M 2 Replies Last reply
          0
          • J JoeSharp

            hi munty have you set the build action property of the file to Embedded Resource?

            M Offline
            M Offline
            Muntyness
            wrote on last edited by
            #5

            Tried it as Embedded Resource, Content and None in the Build Action property. Null on all of them :/ - Munty

            1 Reply Last reply
            0
            • J JoeSharp

              hi munty have you set the build action property of the file to Embedded Resource?

              M Offline
              M Offline
              Muntyness
              wrote on last edited by
              #6

              Finally got the damned thing to work. Turns out I could use this line: TextReader tr = new StreamReader(GetType().Assembly.GetManifestResourceStream("Project1.Resources.rar.txt")); After I fiddled with the properties file so that it returned a string instead of a byte array. Wierdly enough I can still get properties and stuff from the file from: Project1.Properties.Resources.rar I just cant do anything like read in from it when using that line. Well it's finished. Thank god for that. - Munty -- modified at 12:46 Friday 17th November, 2006

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups