Reading Embedded Resources

Discussion in 'ASP .Net' started by thomson, Oct 27, 2005.

  1. thomson

    thomson Guest

    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
     
    thomson, Oct 27, 2005
    #1
    1. Advertisements

  2. thomson

    Karl Seguin Guest

    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
     
    Karl Seguin, Oct 27, 2005
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.