Solved

Cann't load XML file in my Class Library using C#...

Posted on 2007-03-19
6
2,536 Views
Last Modified: 2013-11-07
Hi

I have created a new Class Library Project and inside that i have created one folder and added a XML file inside that folder directory. Inside the Class Library Project i have one class file in that class i'm tring to load my XML file inside the directory previously specified. But i'm not able to load the XML file in that class.

Server.MapPath("ErrorMessages.xml")

It shows the name 'Server' does not exist in the current context.

I'm using .NET 2.0 with C#
0
Comment
Question by:Vivek Thangaswamy
6 Comments
 
LVL 4

Expert Comment

by:meenasree
ID: 18754480
you have to call along with the context for eg
context.Server.MapPath("errorMessages.xml:)
0
 
LVL 2

Expert Comment

by:Peter Skov
ID: 18754485
The only MapPath I know of is
        System.Web.Hosting.HostingEnvironment.MapPath("("ErrorMessages.xml");

But is this really what you want? When I want to *load* an XML-file, I use the ReadXml() function in the DataSet class. You have to instantiate the dataset first, like:

        DataSet ds = new DataSet();
        ds.ReadXml("ErrorMessages.xml");
0
 
LVL 11

Author Comment

by:Vivek Thangaswamy
ID: 18754526
Hey

Here i'm using the class library, how can set context here...
One option is "Place the xml in the same folder of bin" and load like this  private const string XML_FILE_NAME = "ErrorMessages.xml";
another is
Create a public property to set the path and get it ...

I want the second option
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 4

Expert Comment

by:meenasree
ID: 18754618
you pass the context to the method in the class library and access it
0
 
LVL 11

Author Comment

by:Vivek Thangaswamy
ID: 18754693
Hi meenasree

Any sample codes???
0
 
LVL 6

Accepted Solution

by:
dash420 earned 500 total points
ID: 18756419
use this line to get the path of executing assembly.

using System.IO;
using System.Reflection;
 
string str = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

This will return <ApplicationPath>/bin/debug or <ApplicationPath>/bin/release depend upon the mode it is running.
So search two level up and search for your Xml Folder. I think this will help you.

Regards,
Dash
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question