Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Embedded Resource File in Code Library called from ASP.Net web pag

Reply
Thread Tools

Embedded Resource File in Code Library called from ASP.Net web pag

 
 
Jay Pondy
Guest
Posts: n/a
 
      02-16-2009
I have a class library project that is being used in an ASP.Net web site.

In the library class I have several files containing SQL statements (in a
sql subdirectory) with their 'Build Action' property set to Embedded Resource.

I use the following code to retrieve the SQL statements from these embedded
resources at runtime:

protected string SQLFetch(string fileName)
{
Assembly assembly = Assembly.GetEntryAssembly();

Trace.Assert(assembly != null);

string assemblyName = assembly.GetName().Name;
string resourceName = string.Format("{0}.sql.{1}", assemblyName, fileName);
// Assembly.directory.filename

Trace.Assert(resourceName != null);

Stream stream = assembly.GetManifestResourceStream(resourceName);
string sql = string.Empty;

if (stream == null)
throw new ApplicationException(string.Format("Missing resource '{0}'.",
resourceName));
else
{
using (StreamReader rdr = new StreamReader(stream))
{
sql = rdr.ReadToEnd();
}
return sql;
}
}

When I attempt to call into this library from an ASP.Net web site the
assembly is being returned as NULL.

What do I need to do to either correct this problem or work around it?


 
Reply With Quote
 
 
 
 
Jay Pondy
Guest
Posts: n/a
 
      02-16-2009
Do it this way:

JobItems junk = new JobItems();

Assembly assembly = Assembly.GetAssembly(junk.GetType());




"Jay Pondy" wrote:

> I have a class library project that is being used in an ASP.Net web site.
>
> In the library class I have several files containing SQL statements (in a
> sql subdirectory) with their 'Build Action' property set to Embedded Resource.
>
> I use the following code to retrieve the SQL statements from these embedded
> resources at runtime:
>
> protected string SQLFetch(string fileName)
> {
> Assembly assembly = Assembly.GetEntryAssembly();
>
> Trace.Assert(assembly != null);
>
> string assemblyName = assembly.GetName().Name;
> string resourceName = string.Format("{0}.sql.{1}", assemblyName, fileName);
> // Assembly.directory.filename
>
> Trace.Assert(resourceName != null);
>
> Stream stream = assembly.GetManifestResourceStream(resourceName);
> string sql = string.Empty;
>
> if (stream == null)
> throw new ApplicationException(string.Format("Missing resource '{0}'.",
> resourceName));
> else
> {
> using (StreamReader rdr = new StreamReader(stream))
> {
> sql = rdr.ReadToEnd();
> }
> return sql;
> }
> }
>
> When I attempt to call into this library from an ASP.Net web site the
> assembly is being returned as NULL.
>
> What do I need to do to either correct this problem or work around it?
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any quick solution to display performance diagnostics on every pag Phil Johnson ASP .Net 1 01-31-2008 10:16 AM
Erro no start pag tarcisio ASP .Net 1 12-28-2005 01:24 PM
Resource manager problem: naming for embedded resource. Dirc Khan-Evans ASP .Net 1 10-17-2005 12:52 PM
Write information form a comma separated text file onto an ASP pag Roundy ASP General 6 02-04-2005 12:33 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM



Advertisments