Заметка
Доступ к этой странице требует авторизации. Вы можете попробовать войти в систему или изменить каталог.
Доступ к этой странице требует авторизации. Вы можете попробовать сменить директорию.
Каталоги и файлы можно удалить в изолированном файле хранилища. В хранилище имена файлов и каталогов зависят от операционной системы и указываются относительно корня виртуальной файловой системы. Они не зависят от регистра в операционных системах Windows.
Класс System.IO.IsolatedStorage.IsolatedStorageFile предоставляет два метода удаления каталогов и файлов: DeleteDirectory и DeleteFile. Исключение IsolatedStorageException возникает при попытке удалить файл или каталог, который не существует. Если в имени включен подстановочный знак, DeleteDirectory выбрасывает IsolatedStorageException исключение, и DeleteFile выбрасывает ArgumentException исключение.
Метод завершается ошибкой, если каталог содержит файлы или подкаталоги. Вы можете использовать GetFileNames методы и GetDirectoryNames методы для получения существующих файлов и каталогов. Дополнительные сведения о поиске виртуальной файловой системы хранилища см. в разделе "Практическое руководство. Поиск существующих файлов и каталогов в изолированном хранилище".
Пример
В следующем примере кода создается и удаляется несколько каталогов и файлов.
using System;
using System.IO.IsolatedStorage;
using System.IO;
public class DeletingFilesDirectories
{
public static void Main()
{
// Get a new isolated store for this user domain and assembly.
// Put the store into an isolatedStorageFile object.
IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
Console.WriteLine("Creating Directories:");
// This code creates several different directories.
isoStore.CreateDirectory("TopLevelDirectory");
Console.WriteLine("TopLevelDirectory");
isoStore.CreateDirectory("TopLevelDirectory/SecondLevel");
Console.WriteLine("TopLevelDirectory/SecondLevel");
// This code creates two new directories, one inside the other.
isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory");
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory");
Console.WriteLine();
// This code creates a few files and places them in the directories.
Console.WriteLine("Creating Files:");
// This file is placed in the root.
IsolatedStorageFileStream isoStream1 = new IsolatedStorageFileStream("InTheRoot.txt",
FileMode.Create, isoStore);
Console.WriteLine("InTheRoot.txt");
isoStream1.Close();
// This file is placed in the InsideDirectory.
IsolatedStorageFileStream isoStream2 = new IsolatedStorageFileStream(
"AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt", FileMode.Create, isoStore);
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
Console.WriteLine();
isoStream2.Close();
Console.WriteLine("Deleting File:");
// This code deletes the HereIAm.txt file.
isoStore.DeleteFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt");
Console.WriteLine();
Console.WriteLine("Deleting Directory:");
// This code deletes the InsideDirectory.
isoStore.DeleteDirectory("AnotherTopLevelDirectory/InsideDirectory/");
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/");
Console.WriteLine();
} // End of main.
}
Imports System.IO.IsolatedStorage
Imports System.IO
Public Class DeletingFilesDirectories
Public Shared Sub Main()
' Get a new isolated store for this user domain and assembly.
' Put the store into an isolatedStorageFile object.
Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
IsolatedStorageScope.Domain Or IsolatedStorageScope.Assembly, Nothing, Nothing)
Console.WriteLine("Creating Directories:")
' This code creates several different directories.
isoStore.CreateDirectory("TopLevelDirectory")
Console.WriteLine("TopLevelDirectory")
isoStore.CreateDirectory("TopLevelDirectory/SecondLevel")
Console.WriteLine("TopLevelDirectory/SecondLevel")
' This code creates two new directories, one inside the other.
isoStore.CreateDirectory("AnotherTopLevelDirectory/InsideDirectory")
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory")
Console.WriteLine()
' This code creates a few files and places them in the directories.
Console.WriteLine("Creating Files:")
' This file is placed in the root.
Dim isoStream1 As New IsolatedStorageFileStream("InTheRoot.txt", FileMode.Create, isoStore)
Console.WriteLine("InTheRoot.txt")
isoStream1.Close()
' This file is placed in the InsideDirectory.
Dim isoStream2 As New IsolatedStorageFileStream(
"AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt", FileMode.Create, isoStore)
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
Console.WriteLine()
isoStream2.Close()
Console.WriteLine("Deleting File:")
' This code deletes the HereIAm.txt file.
isoStore.DeleteFile("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/HereIAm.txt")
Console.WriteLine()
Console.WriteLine("Deleting Directory:")
' This code deletes the InsideDirectory.
isoStore.DeleteDirectory("AnotherTopLevelDirectory/InsideDirectory/")
Console.WriteLine("AnotherTopLevelDirectory/InsideDirectory/")
Console.WriteLine()
End Sub
End Class