How to extract a zip file on MAUI Platform.

Sojan 21 Reputation points
2023-02-10T03:41:45.64+00:00

i have my zip files saved in Downloads folder. how can i extract the zip to a folder


        try
        {
            string zipFilename = "coregsbundle.zip";
            string ZipPath = Path.Combine(Android.App.Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).ToString(), zipFilename);
      
            ZipFile.ExtractToDirectory(ZipPath, FileSystem.AppDataDirectory);
 
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message.ToString());
        }

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,624 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,631 Reputation points Microsoft Vendor
    2023-02-10T05:49:36.5833333+00:00

    Hello,

    From native android document: Storage updates in Android 11

    Starting in Android 11, apps that use the scoped storage model can access only their own app-specific cache files

    So, you cannot access the public external download folder.

    You can download your file to the app internal storage, such as FileSystem.AppDataDirectory, then you can use ZipFile.ExtractToDirectory to extract a zip file on MAUI like following code.

           string zipFilename = "coregsbundle.zip";
            string ZipPath = Path.Combine(FileSystem.AppDataDirectory, zipFilename);        ZipFile.ExtractToDirectory(ZipPath, FileSystem.AppDataDirectory);
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.