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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How Do I Copy An Embedded Resource to a Directory?

How Do I Copy An Embedded Resource to a Directory?

Scheduled Pinned Locked Moved C#
questionhardwarelearning
4 Posts 4 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.
  • T Offline
    T Offline
    That Asian Guy
    wrote on last edited by
    #1

    I did some reading about embedded resources but they all dealt with pictures and other runtime functions. How do I copy the file from a resource? Thanks.

    N G realJSOPR 3 Replies Last reply
    0
    • T That Asian Guy

      I did some reading about embedded resources but they all dealt with pictures and other runtime functions. How do I copy the file from a resource? Thanks.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      That Asian Guy wrote:

      How do I copy the file from a resource?

      You get them to a stream using Assembly.GetManifestResourceStream[^] and save the stream to a file.

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • T That Asian Guy

        I did some reading about embedded resources but they all dealt with pictures and other runtime functions. How do I copy the file from a resource? Thanks.

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        See this article: Convert MP3 to EXE[^]

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        1 Reply Last reply
        0
        • T That Asian Guy

          I did some reading about embedded resources but they all dealt with pictures and other runtime functions. How do I copy the file from a resource? Thanks.

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          This assumes your resource is in the executing assembly, and be careful - the "executing assembly" is the assembly in which the code is located :

          ResourceManager rm = new ResourceManager("MyAssemblyName.Properties.Resources",
          Assembly.GetExecutingAssembly());
          byte[] streamViewer = (byte[])rm.GetObject("MightyViewer");
          if (streamViewer != null)
          {
          // and write the SWF file to disk
          try
          {
          using (FileStream streamTarget = new FileStream(viewerFile,
          FileMode.Create,
          FileAccess.ReadWrite,
          FileShare.None))
          using (BinaryWriter writer = new BinaryWriter(streamTarget))
          {
          // as an added bonus, this is how you hide a resource file so
          // the user doesn't know it's there.
          File.SetAttributes(viewerFile, File.GetAttributes(viewerFile) |
          FileAttributes.Hidden);
          writer.Write(streamViewer);
          }
          }
          catch (Exception ex)
          {
          if (ex != null) {};
          }
          }

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          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