Solved

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

Posted on 2007-03-19
6
2,596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

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 shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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