Forum Xamarin.Mac


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Copy file from Resources to Library\Application Support

ShammyLevvaShammyLevva Member ✭✭
edited January 2019 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

    public static extern IntPtr NSHomeDirectory();

    public static string ContainerDirectory
            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 Member ✭✭
    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");


Sign In or Register to comment.