14

I can't seem to find an equivalent in Nancy for System.Web.HttpContext.Current.Server.MapPath() in the Nancy framework.

I just want to load a textfile relative to the application service.

I see this in the assembly

using Nancy;
using System;

namespace Nancy.Hosting.Self
{
    public class FileSystemRootPathProvider : IRootPathProvider, IHideObjectMembers
    {
        public FileSystemRootPathProvider();

        public string GetRootPath();
    }
}

I'm not sure how to use.

update: I just figured out anything I need to load can just be read/written from the bin/relase/ directory. Is that the assumed way to do it in a Nancy Self Hosting environment? I guess that would make sense.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117

2 Answers2

11

You can take a dependency on IRootPathProvider and use that to call GetRootPath() that will give you the root of your application and you can add from there (I would recommend using Path.Combine)

TheCodeJunkie
  • 9,378
  • 7
  • 43
  • 54
0

If you need this in a static class (such as an HtmlHelpers extension) where the IRootPathProvider dependency can't be injected, at least AFAIK, you can use AppDomain.CurrentDomain.BaseDirectory which is what DefaultRootPathProvider uses under the hood for .Net 4.x: https://github.com/NancyFx/Nancy/blob/master/src/Nancy/DefaultRootPathProvider.cs

webXL
  • 1,630
  • 1
  • 15
  • 21