Jump to content

cbox


Recommended Posts

Posted

I use a function for that. I think this is it.

 

 

/// <summary>
/// Extracts an embedded file out of a given assembly.
/// </summary>
/// <param name="assemblyName">The namespace of you assembly.</param>
/// <param name="fileName">The name of the file to extract.</param>
/// <returns>A stream containing the file data.</returns>
public static Stream GetEmbeddedFile(string assemblyName, string fileName)
{
   try
   {
       System.Reflection.Assembly a = System.Reflection.Assembly.Load(assemblyName);
       Stream str = a.GetManifestResourceStream(assemblyName + "." + fileName);
          
       if(str == null)
           throw new Exception("Could not locate embedded resource '" + fileName + "' in assembly '" + assemblyName + "'");
       return str;
   }
   catch(Exception e)
   {
       throw new Exception(assemblyName + ": " + e.Message);
   }
}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...