Copy file from Resources to Library\Application Support

ShammyLevvaShammyLevva Member ✭✭
edited January 27 in Xamarin.Mac

Hi there,

I have a SQLite database file that I have a default version of in my Resources directory that is set to copy to the output directory on build.

On app startup I check to see if the user already has my sqlite database file in place if not I want to copy the default file from the resource directory to the user's Library\Application Support directory which I understand is where my sandboxed application can store user data.

What I've not been able to work out programatically is where is my Resource directory path is so I can issue a copy command. I looked at NSHomeWindow() and sample code

[System.Runtime.InteropServices.DllImport("/System/Library/Frameworks/Foundation.framework/Foundation")]
    public static extern IntPtr NSHomeDirectory();

    public static string ContainerDirectory
    {
        get
        {
            return ((NSString)ObjCRuntime.Runtime.GetNSObject(NSHomeDirectory())).ToString();
        }
    }

And am assuming that I use ContainerDirectory as the string representation? However that doesn't seem to point to where my Resources folder is when the app is running.

Best Answer

  • ShammyLevvaShammyLevva ✭✭
    Accepted Answer

    Thanks but that doesn't really address the issue.

    My app is new it has ALWAYS been sandboxed and I can read and write to the sandboxed folder that is not my issue.

    My issue is that I deploy a file as part of the App - an empty database. In my development environment that file resides in the Resources folder.

    A bit of digging in case it helps anyone in future. I was able to get the path via...

    Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location), @"../Resources");

Answers

Sign In or Register to comment.