Solved

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

Posted on 2007-03-19
6
2,553 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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