Como: Excluir repositórios no armazenamento isolado

A classe IsolatedStorageFile fornece dois métodos para excluir arquivos de armazenamento isolado:

  • O método de instância Remove() não recebe qualquer argumento e exclui o armazenamento que o chama. Nenhuma permissão é necessária para essa operação. Qualquer código que possa acessar o armazenamento pode excluir qualquer ou todos os dados dentro dele.

  • O método estático Remove(IsolatedStorageScope) usa o valor de enumeração User e exclui todos os armazenamentos para o usuário que está executando o código. Esta operação exige a permissão IsolatedStorageFilePermission para o valor AdministerIsolatedStorageByUser.

Exemplo

O exemplo de código a seguir demonstra o uso dos métodos Remove estático e de instância . A classe obtém dois armazenamentos; uma é isolado para o usuário e o assembly, e o outro é isolado para o usuário, domínio e assembly. O armazenamento de usuário, domínio e assembly é excluído chamando o método Remove() do arquivo de armazenamento isolado isoStore1. Em seguida, todos os armazenamentos restantes para o usuário são excluídos chamando o método estático Remove(IsolatedStorageScope).

using namespace System;
using namespace System::IO::IsolatedStorage;

public ref class DeletingStores
{
public:
    static void Main()
    {
        // Get a new isolated store for this user, domain, and assembly.
        // Put the store into an IsolatedStorageFile object.

        IsolatedStorageFile^ isoStore1 =  IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
            IsolatedStorageScope::Domain | IsolatedStorageScope::Assembly, (Type ^)nullptr, (Type ^)nullptr);
        Console::WriteLine("A store isolated by user, assembly, and domain has been obtained.");

        // Get a new isolated store for user and assembly.
        // Put that store into a different IsolatedStorageFile object.

        IsolatedStorageFile^ isoStore2 = IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
            IsolatedStorageScope::Assembly, (Type ^)nullptr, (Type ^)nullptr);
        Console::WriteLine("A store isolated by user and assembly has been obtained.");

        // The Remove method deletes a specific store, in this case the
        // isoStore1 file.

        isoStore1->Remove();
        Console::WriteLine("The user, domain, and assembly isolated store has been deleted.");

        // This static method deletes all the isolated stores for this user.

        IsolatedStorageFile::Remove(IsolatedStorageScope::User);
        Console::WriteLine("All isolated stores for this user have been deleted.");
    } // End of Main.
};

int main()
{
    DeletingStores::Main();
}
using System;
using System.IO.IsolatedStorage;

public class DeletingStores
{
    public static void Main()
    {
        // Get a new isolated store for this user, domain, and assembly.
        // Put the store into an IsolatedStorageFile object.

        IsolatedStorageFile isoStore1 =  IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
        Console.WriteLine("A store isolated by user, assembly, and domain has been obtained.");

        // Get a new isolated store for user and assembly.
        // Put that store into a different IsolatedStorageFile object.

        IsolatedStorageFile isoStore2 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly, null, null);
        Console.WriteLine("A store isolated by user and assembly has been obtained.");

        // The Remove method deletes a specific store, in this case the
        // isoStore1 file.

        isoStore1.Remove();
        Console.WriteLine("The user, domain, and assembly isolated store has been deleted.");

        // This static method deletes all the isolated stores for this user.

        IsolatedStorageFile.Remove(IsolatedStorageScope.User);
        Console.WriteLine("All isolated stores for this user have been deleted.");
    } // End of Main.
}
Imports System.IO.IsolatedStorage

Public Class DeletingStores
    Public Shared Sub Main()
        ' Get a new isolated store for this user, domain, and assembly.
        ' Put the store into an IsolatedStorageFile object.

        Dim isoStore1 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
            IsolatedStorageScope.Domain Or IsolatedStorageScope.Assembly, Nothing, Nothing)
        Console.WriteLine("A store isolated by user, assembly, and domain has been obtained.")

        ' Get a new isolated store for user and assembly.
        ' Put that store into a different IsolatedStorageFile object.

        Dim isoStore2 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
            IsolatedStorageScope.Assembly, Nothing, Nothing)
        Console.WriteLine("A store isolated by user and assembly has been obtained.")

        ' The Remove method deletes a specific store, in this case the
        ' isoStore1 file.

        isoStore1.Remove()
        Console.WriteLine("The user, domain, and assembly isolated store has been deleted.")

        ' This static method deletes all the isolated stores for this user.

        IsolatedStorageFile.Remove(IsolatedStorageScope.User)
        Console.WriteLine("All isolated stores for this user have been deleted.")

    End Sub
End Class

Confira também