Resource file question!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CSharper

    Resource file question!

    I am using VS2008 C#3.0 and I would like to know if some one can help
    me wiith the following 2 questions;
    1. I have a XML file called test.xml file in resource and I would like
    to how can I read the xml file wihtout extracting it to a external
    file? I would like to load the object into memory and use it from
    there.
    2. I am planning to have too many data files in the resource file, is
    it possible to compress the resource file and then use it?

    Thanks.
  • Peter Duniho

    #2
    Re: Resource file question!

    On Fri, 21 Mar 2008 13:53:57 -0700, Peter Duniho
    <NpOeStPeAdM@nn owslpianmk.comw rote:
    I don't recall the specifics off the top of my head, but it should be
    possible to get a MemoryStream from a binary resource. So if you just
    treat the XML file resource as a binary resource, you should be able to
    wrap that in a MemoryStream and then just read it normally as a regular
    stream.
    FYI...I took a quick look and sure enough the binary resource shows up as
    a regular byte[]. So you can just use the MemoryStream constructor that
    takes a byte[] array as the source.

    Comment

    • Peter Duniho

      #3
      Re: Resource file question!

      On Fri, 21 Mar 2008 17:54:53 -0700, Jeroen Mostert <jmostert@xs4al l.nl>
      wrote:
      I wasn't looking for a fight along the "my idea is better than yours"
      divide.
      Nor am I. It's just that inexperienced programmers too often get caught
      up in the "let's make this optimal" approach that it's worth pointing out
      at opportune moments that just because something is more performant, that
      doesn't mean it's the best approach.

      I don't have a problem with your contribution, but that doesn't mean I
      think it should be left without some additional commentary pointing out
      that in at least what should be a typical case (ie relatively small
      resources), it's likely to be better to choose a simpler option.

      I'm sure it wasn't your intent, but describing the alternatives you
      suggested as having "saving the overhead..." carries an implication that
      it's a better solution in an objective, unqualified way. In fact, of
      course, it's only "better" in certain context, context I think was worth
      pointing out.
      Or a discussion on things that I hope everyone can decide for their own.
      When all of the facts, they can.
      >But you're right...if someone really wants to get a stream directly,
      >they can.
      >>
      Let's promote this to my main point and forget about my ill-advised
      dropping of the "o" word, lest I be branded as an optimization bum and
      an enemy of simplicity for the rest of my life, which would be a shame.
      Yes, indeed. :)

      Pete

      Comment

      Working...