次の方法で共有


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

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

  • Remove()インスタンス メソッドは引数を受け取らず、それを呼び出すストアを削除します。 この操作にはアクセス許可は必要ありません。 ストアにアクセスできるコードは、その中のデータの一部またはすべてを削除できます。

  • 静的メソッド Remove(IsolatedStorageScope) は、 User 列挙値を受け取り、コードを実行しているユーザーのすべてのストアを削除します。 この操作には、IsolatedStorageFilePermission権限がAdministerIsolatedStorageByUser値に対して必要です。

次のコード例は、静的メソッドとインスタンス Remove メソッドの使用方法を示しています。 クラスは 2 つのストアを取得します。1 つはユーザーとアセンブリ用に分離され、もう 1 つはユーザー、ドメイン、およびアセンブリ用に分離されます。 その後、分離ストレージ ファイル Remove()isoStore1 メソッドを呼び出すことによって、ユーザー、ドメイン、アセンブリ ストアが削除されます。 その後、ユーザーの残りのストアはすべて、静的メソッド Remove(IsolatedStorageScope)を呼び出すことによって削除されます。

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

こちらも参照ください