次の方法で共有


方法 : 分離ストレージでストアを削除する

IsolatedStorageFile には、分離ストレージ ファイルを削除するための 2 つのメソッドが用意されています。

  • インスタンス メソッド Remove は、引数を受け取らず、呼び出したストアを削除します。 この操作には、アクセス許可は不要です。 このストアにアクセスできるコードなら、どのようなコードでも、そのストア内のすべてのデータを削除できます。

  • 静的メソッド Remove は、IsolatedStorageScope の値 User を受け取り、このコードを実行しているユーザーに割り当てられているすべてのストアを削除します。 この操作には、IsolatedStorageContainment の値 AdministerIsolatedStorageByUser に対する IsolatedStorageFilePermission アクセス許可が必要です。

DeletingStores の例

静的メソッドとインスタンス メソッドの Remove の使い方を示すコード例を次に示します。 Remove クラスは、2 つのストアを取得します。1 つはユーザーおよびアセンブリ別に分離されたストアで、もう 1 つはユーザー、ドメイン、およびアセンブリ別に分離されたストアです。 その後、ユーザー、ドメイン、およびアセンブリ別のストアを IsolatedStorageFile isoStore1 の Remove メソッドを呼び出して削除します。 次に、静的メソッド IsolatedStorageFile.Remove を呼び出して、そのユーザーの残りすべてのストアを削除します。

Imports System
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 of Main.
End Class
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.
}
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();
}

参照

参照

IsolatedStorageFile

概念

分離ストレージ