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

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

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

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

DeletingStores の例

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

Imports System
Imports System.IO.IsolatedStorage

Public Module modmain

   Sub Main()

      ' Get an isolated store for user, domain, and assembly and put it into 
      ' an IsolatedStorageFile object.

      Dim isoStore1 As IsolatedStorageFile
      isoStore1 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

      ' Get a store for user and assembly and put it into a different
      ' IsolatedStorageFile object.

      Dim isoStore2 As IsolatedStorageFile
      isoStore2 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly, Nothing, Nothing)

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

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


      ' 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 Module
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.

}

参照

関連項目

IsolatedStorageFile

その他の技術情報

分離ストレージ作業の実行