Relative paths with fetch in Javascript

When you say fetch(‘data.json’) you are effectively requesting since it is relative to the page you’re are making the request from. You should lead with forward slash, which will indicate that the path is relative to the domain root: fetch(‘/js/data.json’). Or fully qualify with your domain fetch(‘’).

How to ensure there is trailing directory separator in paths?

You can easily ensure the behaviour you desire by using TrimEnd: var baseDir = AppDomain.CurrentDomain.BaseDirectory .TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; To be optimally efficient (by avoiding extra allocations), check that the string doesn’t end with a \ before making changes, since you won’t always need to: const string sepChar = Path.DirectorySeparatorChar.ToString(); const string altChar = Path.AltDirectorySeparatorChar.ToString(); var …

Read more

Determine via C# whether a string is a valid file path

You can use the FileInfo constructor. It will throw a ArgumentException if “The file name is empty, contains only white spaces, or contains invalid characters.” It can also throw SecurityException or UnauthorizedAccessException, which I think you can ignore if you’re only concerned about format. Another option is to check against Path.GetInvalidPathChars directly. E.g.: boolean possiblePath …

Read more

Adding system header search path to Xcode

We have two options. Look at Preferences->Locations->”Custom Paths” in Xcode’s preference. A path added here will be a variable which you can add to “Header Search Paths” in project build settings as “$cppheaders”, if you saved the custom path with that name. Set HEADER_SEARCH_PATHS parameter in build settings on project info. I added “${SRCROOT}” …

Read more

File path for project files?

You would do something like this to get the path “Data\ich_will.mp3” inside your application environments folder. string fileName = “ich_will.mp3″; string path = Path.Combine(Environment.CurrentDirectory, @”Data\”, fileName); In my case it would return the following: C:\MyProjects\Music\MusicApp\bin\Debug\Data\ich_will.mp3 I use Path.Combine and Environment.CurrentDirectory in my example. These are very useful and allows you to build a path based …

Read more