Forum Xamarin.Forms

How to delete images from the filesystem?

Murilo0121Murilo0121 BRMember ✭✭
edited December 2016 in Xamarin.Forms

Hello.
I'm tryng to delete some image from my app, but I can't find anything that help me to do it.
I'm using xamarin forms.

I would like to delete a picture after take it.

After taking the photo, with de following code:

var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{SaveToAlbum = false,
CustomPhotoSize = 50,
CompressionQuality = 50,
PhotoSize = new Plugin.Media.Abstractions.PhotoSize()
});

The images was saved inside the directory:

Android\data\MYAPP.Droid\files\Pictures

I would like to know if there someway to delete this images with the xamarin forms. And if will works in the iOS and WP to.

Best Answers

Answers

  • Murilo0121Murilo0121 BRMember ✭✭

    I'm using System.IO

    But, i cannot use the System.IO.File

  • VaibhavPatilVaibhavPatil USMember ✭✭

    try this

    `public static void Delete(String path) {
    
            System.IO.File.Delete(path);
    
        }`
    
  • BushbertBushbert Member ✭✭✭

    I have just come across this and System.IO.File.Delete works just fine. If you're using the CrossMedia plugin, you need to make sure you have disposed of the file object first, otherwise System.IO.File.Delete will fail as the file is still locked.

       var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {SaveToAlbum = false,
        CustomPhotoSize = 50,
        CompressionQuality = 50,
        PhotoSize = new Plugin.Media.Abstractions.PhotoSize()
        });
    
    
    var filePath = file.Path;
    file.Dispose();
    System.IO.File.Delete(filePath);
    
Sign In or Register to comment.