Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1086791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:51:25+00:00 2026-05-16T22:51:25+00:00

I have a static class in a folder off root in my solution. In

  • 0

I have a static class in a folder off root in my solution. In that static class’ folder, there’s a subfolder containing XML files. So I’ve got these files:

/PartialViews/Header/MyStaticClass.cs
/PartialViews/Header/Config/en-US.xml
/PartialViews/Header/Config/jp-JP.xml
...

I’m having trouble using XDocument.Load() with those XML files. Specifically, I’m trying to load the XML files from the static constructor of MyStaticClass.

XDocument.Load() can’t seem to find the files, however. I’ve tried all these and none work:

static MyStaticClass()
{
    XDocument doc;

    // These all throw exceptions relating to directory not found
    doc = XDocument.Load("/Config/en-US.xml");
    doc = XDocument.Load(@"\Config\en-US.xml");
    doc = XDocument.Load("/PartialViews/Header/Config/en-US.xml");
    doc = XDocument.Load(@"\PartialViews\Header\Config\en-US.xml");
}

I also tried using Assembly.GetExecutingAssembly().Location and Assembly.GetEntryAssembly().Location before the relative path, but the assembly resolved by Assembly is always a .NET library (because the type is being initialized?).

How can I load the file without changing its location in the solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:51:26+00:00Added an answer on May 16, 2026 at 10:51 pm

    In ASP.NET you should use Server.MapPath() to find all local files.

    string relPath = "~/PartialViews/Header/Config/en-US.xml";
    string absPath = Server.MapPath(relPath);
    
    XDocument doc = XDocument.Load(absPath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have all my static files in a folder called html in the root
I have a static class that I use as my Data Utils for my
I have a static class that looks like this: namespace Argus { static class
So I have a static class that is supposed to be used as a
I have a static Preferences class that hold some application preferences and stuff like
I have an windows service that monitors a folder for new files being created.when
i have a Class called Services in the App_code folder that contain Method like
say I have jcifs-1.3.14.jar in my lib folder, and I have a class that
I have ASP.net website. In App_Code folder I have class that has extension methods.
I have a static method (in the class CommonHelper in the namespace Common) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.