Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-19
6
Medium Priority
?
2,634 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 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