I used to store the resources in the actual project, but I've switched to using a resource file instead. Originally I could ready the bytes for a file, but I'm finding it difficult doing this with a resource file. Any suggestions would be greatly appreciated.
+3
A:
public static byte[] ReadResource(string resourceName)
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
{
byte[] buffer = new byte[1024];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = s.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
Anton
2009-11-10 16:45:37
The files I want to read our added as links and in a folder in the project called Resources. Using this function keep causing an object reference error
williamtroup
2009-11-11 08:48:26
Then load the assembly with the resources instead of the current execution context.
Anton
2009-11-12 05:23:31