public void DeleteFile_ThrowsIsolatedStorageException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <IsolatedStorageException>(() => isf.DeleteFile("foo")); } }
public void MoveFile_Deleted_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <InvalidOperationException>(() => isf.MoveFile("foo", "bar")); } }
public void DeleteRemovedDirectory_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <InvalidOperationException>(() => isf.DeleteDirectory("foo")); } }
public void GetLastAccessTime_Removed_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <InvalidOperationException>(() => isf.GetLastAccessTime("foo")); } }
public void CreateRemovedFile_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <InvalidOperationException>(() => isf.CreateFile("foo")); } }
public void CreateDirectory_ThrowsIsolatedStorageException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <IsolatedStorageException>(() => isf.CreateDirectory("foo")); } }
public void OpenFile_Deleted_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <InvalidOperationException>(() => isf.OpenFile("foo", FileMode.Create)); Assert.Throws <InvalidOperationException>(() => isf.OpenFile("foo", FileMode.Create, FileAccess.ReadWrite)); Assert.Throws <InvalidOperationException>(() => isf.OpenFile("foo", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)); } }
// Remove all stores of a particular type. public static void Remove(IsolatedStorageScope scope) { IsolatedStorageFile file = GetStore(scope); try { file.Remove(); } finally { file.Close(); } }
[System.Security.SecurityCritical] // auto-generated #endif public void Remove() { #if !FEATURE_LEGACYNETCF bool removedAll = true; FileLock groupLock = FileLock.GetFileLock(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_LockPathPrefix), IsolatedStorageFile.s_GroupPathPrefix + "-" + m_ObfuscatedId); try { groupLock.Lock(); foreach (string storeDir in Directory.UnsafeGetDirectories(Path.Combine(IsolatedStorageFile.IsolatedStorageRoot, IsolatedStorageFile.s_StorePathPrefix), "*", SearchOption.TopDirectoryOnly)) { string groupFile = Path.Combine(storeDir, IsolatedStorageFile.s_GroupFileName); if (m_ObfuscatedId.Equals(File.UnsafeReadAllText(groupFile))) { IsolatedStorageFile f = IsolatedStorageFile.GetUserStoreFromGroupAndStorePath(Group, storeDir); removedAll = removedAll & f.TryRemove(); } } IsolatedStorageFile.TouchFile(Path.Combine(m_GroupPath, IsolatedStorageFile.s_CleanupFileName)); if (removedAll) { IsolatedStorageAccountingInfo.RemoveAccountingInfo(m_GroupPath); File.UnsafeDelete(Path.Combine(m_GroupPath, IsolatedStorageFile.s_IdFileName)); File.UnsafeDelete(Path.Combine(m_GroupPath, IsolatedStorageFile.s_CleanupFileName)); Directory.UnsafeDelete(m_GroupPath, false); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } finally { groupLock.Unlock(); } #else // !FEATURE_LEGACYNETCF try { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { isf.Remove(); } } catch (IOException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } catch (UnauthorizedAccessException) { // There isn't anything we can really do about this. Ignoring these sorts of issues shouldn't lead to corruption. } #endif // !FEATURE_LEGACYNETCF }
internal static void ClearSlFiles(string rFileName) { System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (rFileName == null || rFileName.TrimEnd() == "") { isf.Remove(); } else { if (isf.FileExists(rFileName)) { isf.DeleteFile(rFileName); } } isf.Dispose(); }
// use the caller stack to execute some write operations private void Write (IsolatedStorageFile isf) { isf.CreateDirectory ("testdir"); string filename = Path.Combine ("testdir", "file"); using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream (filename, FileMode.Create, isf)) { } isf.DeleteFile (filename); isf.DeleteDirectory ("testdir"); try { isf.Remove (); } catch (IsolatedStorageException) { // fx 1.x doesn't like removing when things "could" still be in use } }