locked
data file in local folder

    Question

  • Hi, everybody. I would like to place an xml readonly file to the local folder during the deployment of the app so my app can retrieve data from there. How can I do it? Let me mention that the file already exists, I don't want to create it. Thank very much.
    Tuesday, June 17, 2014 9:40 AM

Answers

  • you cant during deployments (i assume installing from the windows store) you can do this during the startup of your application. in the app.xaml.cs:

    try
                    {
                        var sourcefile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///assets/file.text"));
                        await sourcefile.CopyAsync(ApplicationData.Current.LocalFolder, "targetfilename", NameCollisionOption.FailIfExists);
                    }
                    catch
                    {
    
                    }
    you place the file in the asset folder and during startup its copied to the localfolder if it not exist


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Tuesday, June 17, 2014 10:20 AM

All replies

  • you cant during deployments (i assume installing from the windows store) you can do this during the startup of your application. in the app.xaml.cs:

    try
                    {
                        var sourcefile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///assets/file.text"));
                        await sourcefile.CopyAsync(ApplicationData.Current.LocalFolder, "targetfilename", NameCollisionOption.FailIfExists);
                    }
                    catch
                    {
    
                    }
    you place the file in the asset folder and during startup its copied to the localfolder if it not exist


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Tuesday, June 17, 2014 10:20 AM
  • Thank you very much. It worked like a charm.
    Tuesday, June 17, 2014 7:46 PM
  • You want to reduce as much processing as possible at app startup, so checking on this later is better if you don't need it immediately. Trying to open it when needed and then copying only if that failed is often a good tactic.
    Tuesday, June 17, 2014 8:07 PM
    Owner