0

I have a C# project with a couple of files in there and a class who retrieves some data from those files.

I am calling that class in an ASP.NET MVC 5 web app and getting the System.IO.FileNotFoundException, obviously. I just can't figure out how to tweek my code to work.

Here is a snipped of code from the class who reads the files.

    XmlSchemaSet schemas = new XmlSchemaSet();
    schemas.Add("urn:OECD:StandardAuditFile-Tax:PT_" + version, 
               @"XSD\SAFT\SAFTPT" + version + ".xsd");

Calling the method from the website (isolated project), it cannot find the XSD file. It is being copied to the website's bin folder tho.

hpinhal
  • 512
  • 6
  • 22
  • You're using a relative path; an IIS site runs by default in `C:\Windows\System32`. See [Get current directory in asp.net mvc](http://stackoverflow.com/questions/9393597/get-current-directory-in-asp-net-mvc) to map the path relative to your site. – CodeCaster Jul 06 '15 at 10:19
  • This is not duplicated because I do not have access to the controller from where the file is being loaded. It is in an isolated class library.... Therefore, no access to the controller or Request. – hpinhal Jul 06 '15 at 10:21
  • Then you need to either make the path a parameter and pass that from the controller, or change the working directory. Show this class and method and how you use it from your controller, or see [Working folder in ASP.NET](http://stackoverflow.com/questions/2196384/working-folder-in-asp-net) to set the working folder if you want to keep using relative paths. – CodeCaster Jul 06 '15 at 10:23
  • Well, this was my solution. `Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, @"XSD\SAFT\SAFTPT" + version + ".xsd")` – hpinhal Jul 06 '15 at 10:27

0 Answers0