I am having difficulties copying some files from my application Resources folder:
var myDocuments = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Library");
// Confirm these paths are OK for iOS too
var root = Path.Combine(myDocuments, "VisitsRota.MacOS");
var styles = Path.Combine(root, "Styles");
var stylesheet = Path.Combine(styles, "ElderlyInfirm-Schedule-v1.css");
var db = Path.Combine(root, "ElderlyInfirmRotaData.xml");
var defaultroot = Path.Combine( ".", "Resources");
// Main folder
if (!Directory.Exists(root))
{
Directory.CreateDirectory(root);
}
// Database
if (!File.Exists(db))
{
var defaultdb = Path.Combine(defaultroot, "ElderlyInfirmRotaData.xml");
File.Copy(defaultdb, db);
}
// Styles folder
if (!Directory.Exists(styles))
{
Directory.CreateDirectory(styles);
}
// Stylesheet
if (!File.Exists(stylesheet))
{
var defaultstylesheet = Path.Combine(defaultroot, "Styles", "ElderlyInfirm-Schedule-v1.css");
File.Copy(defaultstylesheet, stylesheet);
}
The problem is determining the application folders Resources folder, At the moment I get this exception:
What is the correct way to get to the Resources folder (for either iOS or macOS)?
In the IDE I only see just the one Resource folder:
Both of my resources have a Build Action set to Content.
Thank you for pointing me in the right direction to resolve this.
I tried using the result from:
public static string GetExecutingDirectoryName()
{
var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase);
return new FileInfo(location.AbsolutePath).Directory.FullName;
}
It was completely wrong.
I am running the app in the Debugger in VS for Mac (macOS build).
I assume that using the Resource folder for these files was OK. Unless there is a better way to do this?