2

I've tried these options:

var resourcePath = "data.xml";
Application files are located in: c:/MyApp/bin/Release.
AppDomain.CurrentDomain.BaseDirectory refers to "c:/MyApp" folder.
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath refers to "c:/MyApp/bin/Release" folder.
HttpContext.Current.Server.MapPath(resourcePath) refers to http://www.domain.com/MyApp/data.xml

Only the PrivateBinPath works but by definition it can contain multiple bin directories so maybe I shouldn't be using this.

how's the standard approach for a Web API app to access a file in the Bin folder?

4
  • Standard dictates to have data files in APP_DATA folder not in BIN folder. Could you explain why you need this file in that folder? Commented Aug 4, 2014 at 7:32
  • yes I agree but this is a legacy app with asp.net 3.5. Regardless, how'd you access the file after being copied in the bin folder? Commented Aug 4, 2014 at 7:39
  • 1
    Did you try HttpContext.Current.Server.MapPath("~/bin", "data.xml")? Commented Aug 4, 2014 at 8:11
  • Many thanks, yes worked :) Commented Aug 4, 2014 at 8:27

1 Answer 1

5

If the BIN folder is a direct subfolder of your root site then

string resourceFile = HttpContext.Current.Server.MapPath("~/bin", "data.xml");

should give you the dedidered path (and works also if you move your app on an external hosting site). Of course, being BIN a protected folder you should be sure to have the required permissions to read or write files in this path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.