Code Example: Embedded resource extraction

יום שבת, פברואר 23, 2008

If .Net project contains embedded resources, we can extract them at run-time (for internal-in-program usage or to save as files). Embedded resource can be attached file of any type (popular types: texts, images, sounds). For example, .Net project contains embedded "License Agreement" text file: File properties: This code shows how to load embedded text file into string "license": public void ExtractResources() { Stream sin = Assembly.GetExecutingAssembly().GetManifestResourceStream("SegevSystems.Setup.Files.LICENSE AGREEMENT.TXT"); StreamReader r = new StreamReader(sin); string license = r.ReadToEnd(); r.Close(); r.Dispose(); sin.Close(); sin.Dispose(); } // "SegevSystems.Setup.Files" represents namespace where resources are located This code shows how to save all embedded resources into files: public void ExtractResources() { try...
no comments