luki
luki

Reputation: 49

PCLStorage - How to get path to writable folder?

I need download and save file. I using this code (with Xam.Plugins.DownloadManager and PCLStorage libraries):

public static string DownloadNewXml(string LinkToFile, string PathFile)
    {
        var downloadManager = CrossDownloadManager.Current;
        CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file => {
           return PathFile;
        });
        try
        {
            var file = downloadManager.CreateDownloadFile(LinkToFile);
            downloadManager.Start(file);
            return "ok";
        }
        catch(Exception e)
        {
            return e.ToString() ;
        }
    }

Where PathFile is: FileSystem.Current.LocalStorage.Path + "file.xml"; This code throw exception on Android and UWP - i can't write file to this path (FileSystem.Current.LocalStorage.Path). So I have a question. How to get path to writable folder for my application on all platforms (Android, UWP, iOS)? Please help.

Upvotes: 0

Views: 1765

Answers (1)

Taras Shevchuk
Taras Shevchuk

Reputation: 336

Try use Path.Combine(FileSystem.Current.LocalStorage.Path, "file.xml") instead

Upvotes: 1

Related Questions