473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Determine namespace of assembly

The following code works. My problem is that I don't want to have to
hardcode the string that I set resourceName to in the code. Is there a way
for me to determine the namespace of the assembly from the oAssembly object?
All I want is the string "MyTopNamespace.Helpers." I will of course hard
code the USStates.xml.

namespace MyTopNamespace.Helpers.SpecialCollections
{
public sealed class USCollections
{

private static DataTable FetchStateData()
{
// open the executing assembly
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

// create stream for resource in assembly
// Make sure that the resource's build action in the project is set to
'Embedded Resource'
string resourceName = "MyTopNamespace.Helpers.USStates.xml";
System.IO.Stream docStream =
oAssembly.GetManifestResourceStream(resourceName);

DataSet ds = new DataSet();
ds.ReadXml(docStream, XmlReadMode.Auto);
ds.Tables[0].TableName = "USStates";

return ds.Tables[0].Copy();
}
}
}

Nov 15 '05 #1
3 7269
I found out the way to do it if I make the function non-static:

this.GetType().Namespace

will give me what I need. Is there a way to do it when the function is
static?
"Chris Becker" <sl*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The following code works. My problem is that I don't want to have to
hardcode the string that I set resourceName to in the code. Is there a way for me to determine the namespace of the assembly from the oAssembly object? All I want is the string "MyTopNamespace.Helpers." I will of course hard
code the USStates.xml.

namespace MyTopNamespace.Helpers.SpecialCollections
{
public sealed class USCollections
{

private static DataTable FetchStateData()
{
// open the executing assembly
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

// create stream for resource in assembly
// Make sure that the resource's build action in the project is set to 'Embedded Resource'
string resourceName = "MyTopNamespace.Helpers.USStates.xml";
System.IO.Stream docStream =
oAssembly.GetManifestResourceStream(resourceName);

DataSet ds = new DataSet();
ds.ReadXml(docStream, XmlReadMode.Auto);
ds.Tables[0].TableName = "USStates";

return ds.Tables[0].Copy();
}
}
}

Nov 15 '05 #2
have you tried something like:

typeof(YourType).Namespace ?
"Chris Becker" <sl*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found out the way to do it if I make the function non-static:

this.GetType().Namespace

will give me what I need. Is there a way to do it when the function is
static?
"Chris Becker" <sl*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The following code works. My problem is that I don't want to have to
hardcode the string that I set resourceName to in the code. Is there a way
for me to determine the namespace of the assembly from the oAssembly

object?
All I want is the string "MyTopNamespace.Helpers." I will of course hard code the USStates.xml.

namespace MyTopNamespace.Helpers.SpecialCollections
{
public sealed class USCollections
{

private static DataTable FetchStateData()
{
// open the executing assembly
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

// create stream for resource in assembly
// Make sure that the resource's build action in the project is

set to
'Embedded Resource'
string resourceName = "MyTopNamespace.Helpers.USStates.xml";
System.IO.Stream docStream =
oAssembly.GetManifestResourceStream(resourceName);

DataSet ds = new DataSet();
ds.ReadXml(docStream, XmlReadMode.Auto);
ds.Tables[0].TableName = "USStates";

return ds.Tables[0].Copy();
}
}
}


Nov 15 '05 #3
That works as well... thanks. Since I did change the function into a member
of the object rather than a static function, I will stick with
this.GetType().Namespace so that I don't have to hard code the class's name,
but I will definitely use typeof(typename).Namespace other times.

Thanks for your help.

Chris
"Jeffrey Huntsman" <jhuntsman@__nospam__teletracking.com> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
have you tried something like:

typeof(YourType).Namespace ?
"Chris Becker" <sl*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I found out the way to do it if I make the function non-static:

this.GetType().Namespace

will give me what I need. Is there a way to do it when the function is
static?
"Chris Becker" <sl*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The following code works. My problem is that I don't want to have to
hardcode the string that I set resourceName to in the code. Is there
a
way
for me to determine the namespace of the assembly from the oAssembly

object?
All I want is the string "MyTopNamespace.Helpers." I will of course

hard code the USStates.xml.

namespace MyTopNamespace.Helpers.SpecialCollections
{
public sealed class USCollections
{

private static DataTable FetchStateData()
{
// open the executing assembly
System.Reflection.Assembly oAssembly =
System.Reflection.Assembly.GetExecutingAssembly();

// create stream for resource in assembly
// Make sure that the resource's build action in the project is

set
to
'Embedded Resource'
string resourceName = "MyTopNamespace.Helpers.USStates.xml";
System.IO.Stream docStream =
oAssembly.GetManifestResourceStream(resourceName);

DataSet ds = new DataSet();
ds.ReadXml(docStream, XmlReadMode.Auto);
ds.Tables[0].TableName = "USStates";

return ds.Tables[0].Copy();
}
}
}



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brad | last post by:
My company is setting up a deployment process for implementing .NET Windows applications. One of the standards we want the process to enforce is verifying that the assembly is built in release...
2
by: Mythran | last post by:
In .Net, how can I go about and set a Crystal Reports namespace? Right now they use the Root Namespace (VB) from the project. How can I extend the namespace for a single report (which will be set...
2
by: jw56578 | last post by:
Hi, Is there a way to discover all the classes within a given namespace? thanks
3
by: Guoqi Zheng | last post by:
Dear sir, On some of my pages, I used a <base href="http://www.meetholland.com/"> I need to dynamically determine the base href value to different URL based on user session. I am thinking...
1
by: Phill. W | last post by:
Having changed a VB.Net(2003) DLL project, I'm getting Type Loading problems in other code that uses my DLL. In my source code, I have a Namespace Statement something like this: Namespace...
29
by: Tiraman | last post by:
Hi, I Build my own dll with my own namespace name and i would like to put it in one place but for the project bin folder so all of the projects will be able to use it . i tried to put the dll...
2
by: Jeff Brown | last post by:
Hi, I suspect that this isn't possible, but I figured I'd ask. My project has a root namespace, let's say it's "Root", that applies to almost every source file (which is why I've set it as the...
7
by: Cramer | last post by:
I'm wondering if there is an easy way to programmatically determine if an assembly is installed in the GAC. This would be similar to our ability to easily determine if a file exists...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.