Forum Xamarin Xamarin.Forms

Save docs/images on application folder (or where I have access)

EnricoRossiniEnricoRossini USMember ✭✭✭✭
edited September 2016 in Xamarin.Forms

Hi guys,
I want to create pics and document in a folder (application folder) where I can have access. For example on iOS I'm using

    /// <summary>
    /// Gets the personal folder.
    /// </summary>
    /// <returns>The personal folder.</returns>
    public string GetPersonalFolder() {
        var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        return documentsDirectory.ToString();
    }

and in iTunes I can copy all my files on my local hard disk. I can't find a way to do the same with Android and UWP. In Android I tried all SpecialFolder but I always have an access denied.

Best Answer

  • MabroukMabrouk USMember ✭✭✭
    edited September 2016 Accepted Answer

    In android, that may helps you :

    private string _imageName {get;set;} public string ImageFullPath { get { return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_imageName); } }

    Here, ImageFullPath return a default path that you can use it to save your image.

Answers

  • MabroukMabrouk USMember ✭✭✭
    edited September 2016 Accepted Answer

    In android, that may helps you :

    private string _imageName {get;set;} public string ImageFullPath { get { return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_imageName); } }

    Here, ImageFullPath return a default path that you can use it to save your image.

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    Thanks @Mabrouk
    External storage means SD card?

  • MabroukMabrouk USMember ✭✭✭

    @EnricoRossini not exactly, its for default phone storage.

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    Thanks again @Mabrouk
    It's working perfectly! Do you know how in UWP? :smiley:

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    Thanks again @Mabrouk
    It's working perfectly! Do you know how in UWP? :smiley:

  • MabroukMabrouk USMember ✭✭✭

    @EnricoRossini , Sorry i didnt try UWP before :)

  • MabroukMabrouk USMember ✭✭✭

    @EnricoRossini hi friend , i found this for you, for UWP :
    public async Task SaveTextAsync(string filename, string text) { StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await localFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(sampleFile, text); }

    Hope it helps ;)

  • EnricoRossiniEnricoRossini USMember ✭✭✭✭

    Thank you @Mabrouk
    I'm using this solution but I can't inspect an app folder because in this case the app saves files on its folder on the device.

  • MabroukMabrouk USMember ✭✭✭
    edited September 2016

    @EnricoRossini , Take a look here :)

    StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; // Create a new subfolder in the current folder. // Raise an exception if the folder already exists. string desiredName = "Subfolder"; StorageFolder newFolder = await localFolder.CreateFolderAsync(desiredName, CreationCollisionOption.FailIfExists);

Sign In or Register to comment.