Resource Content

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

    #1

    Resource Content

    Hi All,

    I have created a folder call Resource within my project, I have added a XML
    file into the resource folder, and I set the BuildAction property of the XML
    file to "Embedded Resource". How can I retrieve its content in the runtime?
    Any help is deeply appreciated. Thanks you very much in advance.

    Kate


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Resource Content

    Hi,

    It will be inside the .exe ( or dll )

    You can use this code to retrieve it:

    IIRC the full name would be the namespace +. + the name of the file, not
    100% sure now though.

    m_bitmap = new
    System.Drawing. Bitmap(GetType( ).Assembly.GetM anifestResource Stream(
    "TheNameOfTheIm age.gif" ));



    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation


    "cql90" <cql90@yahoo.co m> wrote in message
    news:OTmM2mhFGH A.524@TK2MSFTNG P09.phx.gbl...[color=blue]
    > Hi All,
    >
    > I have created a folder call Resource within my project, I have added a
    > XML file into the resource folder, and I set the BuildAction property of
    > the XML file to "Embedded Resource". How can I retrieve its content in the
    > runtime? Any help is deeply appreciated. Thanks you very much in advance.
    >
    > Kate
    >[/color]


    Comment

    • cql90

      #3
      Re: Resource Content

      Thanks you very much for your responded, I am deeply appreciated. Your code
      would work well for bitmap, but not for XML file. Take care and have a nice
      day...

      Kate,


      "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
      in message news:uKOk4OiFGH A.3120@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi,
      >
      > It will be inside the .exe ( or dll )
      >
      > You can use this code to retrieve it:
      >
      > IIRC the full name would be the namespace +. + the name of the file, not
      > 100% sure now though.
      >
      > m_bitmap = new
      > System.Drawing. Bitmap(GetType( ).Assembly.GetM anifestResource Stream(
      > "TheNameOfTheIm age.gif" ));
      >
      >
      >
      > --
      > Ignacio Machin,
      > ignacio.machin AT dot.state.fl.us
      > Florida Department Of Transportation
      >
      >
      > "cql90" <cql90@yahoo.co m> wrote in message
      > news:OTmM2mhFGH A.524@TK2MSFTNG P09.phx.gbl...[color=green]
      >> Hi All,
      >>
      >> I have created a folder call Resource within my project, I have added a
      >> XML file into the resource folder, and I set the BuildAction property of
      >> the XML file to "Embedded Resource". How can I retrieve its content in
      >> the runtime? Any help is deeply appreciated. Thanks you very much in
      >> advance.
      >>
      >> Kate
      >>[/color]
      >
      >[/color]


      Comment

      • John Murray

        #4
        Re: Resource Content

        Actually, his call to GetManifestReso urceStream returns what it says --
        a stream .... so whether your are feed that stream to an XML Reader or a
        Bitmap constructor should work equally well.


        cql90 wrote:[color=blue]
        > Thanks you very much for your responded, I am deeply appreciated. Your code
        > would work well for bitmap, but not for XML file. Take care and have a nice
        > day...
        >
        > Kate,
        >
        >
        > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
        > in message news:uKOk4OiFGH A.3120@TK2MSFTN GP10.phx.gbl...
        >[color=green]
        >>Hi,
        >>
        >>It will be inside the .exe ( or dll )
        >>
        >>You can use this code to retrieve it:
        >>
        >>IIRC the full name would be the namespace +. + the name of the file, not
        >>100% sure now though.
        >>
        >>m_bitmap = new
        >>System.Drawin g.Bitmap(GetTyp e().Assembly.Ge tManifestResour ceStream(
        >>"TheNameOfThe Image.gif" ));
        >>
        >>
        >>
        >>--
        >>Ignacio Machin,
        >>ignacio.machi n AT dot.state.fl.us
        >>Florida Department Of Transportation
        >>
        >>
        >>"cql90" <cql90@yahoo.co m> wrote in message
        >>news:OTmM2mhF GHA.524@TK2MSFT NGP09.phx.gbl.. .
        >>[color=darkred]
        >>>Hi All,
        >>>
        >>>I have created a folder call Resource within my project, I have added a
        >>>XML file into the resource folder, and I set the BuildAction property of
        >>>the XML file to "Embedded Resource". How can I retrieve its content in
        >>>the runtime? Any help is deeply appreciated. Thanks you very much in
        >>>advance.
        >>>
        >>>Kate
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]

        Comment

        • cql90

          #5
          Re: Resource Content


          My project name is: Test. I did insert a folder call: "Resource" into my
          project. I did insert an XML file into the resource folder, I set the
          BuildAction of XML file to Embedded resource. After all, I do this:

          try

          {

          System.Reflecti on.Assembly _Assembly =
          System.Reflecti on.Assembly.Get ExecutingAssemb ly();

          StreamReader rd = new StreamReader( _Assembly .GetManifestRes ourceStream(
          "Test.Resource. Configuration.x ml" ) );

          }

          catch( Exception Err )

          {

          MessageBox.Show ( Err.Message );

          }

          I am always get an error message said that: the "stream" cannot be null

          Any ways, Thanks you so much for your help, John. I am very appreciated. I
          did try the code but it doen't work. Take care and have a nice day.



          "John Murray" <jmurray@pluck. com> wrote in message
          news:um0d$FkFGH A.3984@TK2MSFTN GP14.phx.gbl...[color=blue]
          > Actually, his call to GetManifestReso urceStream returns what it says --
          > a stream .... so whether your are feed that stream to an XML Reader or a
          > Bitmap constructor should work equally well.
          >
          >
          > cql90 wrote:[color=green]
          >> Thanks you very much for your responded, I am deeply appreciated. Your
          >> code would work well for bitmap, but not for XML file. Take care and have
          >> a nice day...
          >>
          >> Kate,
          >>
          >>
          >> "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
          >> wrote in message news:uKOk4OiFGH A.3120@TK2MSFTN GP10.phx.gbl...
          >>[color=darkred]
          >>>Hi,
          >>>
          >>>It will be inside the .exe ( or dll )
          >>>
          >>>You can use this code to retrieve it:
          >>>
          >>>IIRC the full name would be the namespace +. + the name of the file, not
          >>>100% sure now though.
          >>>
          >>>m_bitmap = new
          >>>System.Drawi ng.Bitmap(GetTy pe().Assembly.G etManifestResou rceStream(
          >>>"TheNameOfTh eImage.gif" ));
          >>>
          >>>
          >>>
          >>>--
          >>>Ignacio Machin,
          >>>ignacio.mach in AT dot.state.fl.us
          >>>Florida Department Of Transportation
          >>>
          >>>
          >>>"cql90" <cql90@yahoo.co m> wrote in message
          >>>news:OTmM2mh FGHA.524@TK2MSF TNGP09.phx.gbl. ..
          >>>
          >>>>Hi All,
          >>>>
          >>>>I have created a folder call Resource within my project, I have added a
          >>>>XML file into the resource folder, and I set the BuildAction property of
          >>>>the XML file to "Embedded Resource". How can I retrieve its content in
          >>>>the runtime? Any help is deeply appreciated. Thanks you very much in
          >>>>advance.
          >>>>
          >>>>Kate
          >>>>
          >>>
          >>>[/color]
          >>[/color][/color]

          Comment

          • Ignacio Machin \( .NET/ C# MVP \)

            #6
            Re: Resource Content

            Hi,

            I have never put the resource file in a folder.
            Do this:

            string[] resources = GetType().Assem bly.GetManifest ResourceNames()


            You can then iterate in all the resources and see how it's named

            Please post back your findings



            --
            Ignacio Machin,
            ignacio.machin AT dot.state.fl.us
            Florida Department Of Transportation


            Comment

            • cql90

              #7
              Re: Resource Content

              Hi Ignacio Machin,

              The reason why I put the resource in the folder because it will be cleanner.
              I have images in one folder, xml files in another folder, and picture in
              other folder. Now, you know why I have to put my xml file in a folder. it
              works if I don't put my xml file in folder and the code look like this:

              // Get the data from XML file and input into the stream

              System.IO.Strea m _stream = _Assembly.GetMa nifestResourceS tream(
              "Test.Configura tion.xml" );

              // Create read stream object so we can read data out from the stream

              StreamReader _streamReader = new StreamReader( _stream );

              // Make file name in current working environment

              string strFilename = AppDomain.Curre ntDomain.BaseDi rectory +
              "Configuration. xml";

              // Create a file to write data from the stream to the file

              StreamWriter _streamWriter = new StreamWriter( strFilename );

              // Read all the data from stream and write to the file

              _streamWriter.W rite( _streamReader.R eadToEnd() );

              // Close when finish

              _streamReader.C lose();

              _streamWriter.C lose();

              // Create temporary process

              System.Diagnost ics.Process _Process = new System.Diagnost ics.Process();

              // Open the notepad file, read data from XML file and then paste data into
              the notepad

              System.Diagnost ics.ProcessStar tInfo _pcInfo = new

              System.Diagnost ics.ProcessStar tInfo( "Notepad.ex e", strFilename );

              _pcInfo.UseShel lExecute = false;

              _pcInfo.Redirec tStandardOutput = true;

              _Process.StartI nfo = _pcInfo;

              // Start Nodepad

              _Process.Start( );

              // Pause right here until the notepad is close

              _Process.WaitFo rExit();

              // Release the temporary process

              _Process.Close( );

              // Create new fileinfo object

              FileInfo _finfos = new FileInfo( strFilename );

              // Delete file

              _finfos.Delete( );


              Thanks you so much for your help, Ignacio. I am greatly appreciated. Take
              care and have a nice day...



              "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
              in message news:%23HfuyjtF GHA.4036@TK2MSF TNGP12.phx.gbl. ..[color=blue]
              > Hi,
              >
              > I have never put the resource file in a folder.
              > Do this:
              >
              > string[] resources = GetType().Assem bly.GetManifest ResourceNames()
              >
              >
              > You can then iterate in all the resources and see how it's named
              >
              > Please post back your findings
              >
              >
              >
              > --
              > Ignacio Machin,
              > ignacio.machin AT dot.state.fl.us
              > Florida Department Of Transportation
              >[/color]


              Comment

              Working...