Reading Embedded Resources

T

thomson

Hi all,
I have added a new Item in my Solution Test.sql which has got
some sql scripts and i have changed the Build Action Property of the
file to embedded Resources


private string GetSql(string Name)

{

// Gets the current assembly.

Assembly Asm = Assembly.GetExecutingAssembly();

// Resources are named using a fully qualified name.

Stream strm =
Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);

// Reads the contents of the embedded file.

StreamReader reader = new StreamReader(strm);

return reader.ReadToEnd();

}


}

i wrote this function to read the Embedded Resource when it executes
the Stream Reader it gives an Error


System.IO.__UnmanagedMemoryStream

Can any one let me know where i went wrong

Thanks in Advance

thomson
 
K

Karl Seguin

A quick guess. You are using Asm.GetName().Name this returns the name of
the assembly, not necessary what you want. What you want is the
Namespace.FileName of your resource. Namespace will be the default
namespace you assigned your assembly. Also, make sure that Name specifies
an extension. You should also look at closing your reader.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top