Solved

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

Posted on 2007-03-19
6
2,459 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
Comment Utility
you have to call along with the context for eg
context.Server.MapPath("errorMessages.xml:)
0
 
LVL 2

Expert Comment

by:Peter Skov
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

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

Author Comment

by:Vivek Thangaswamy
Comment Utility
Hi meenasree

Any sample codes???
0
 
LVL 6

Accepted Solution

by:
dash420 earned 500 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now