Windows phone 7 删除windows phone 7中的独立存储目录

Windows phone 7 删除windows phone 7中的独立存储目录,windows-phone-7,isolatedstorage,Windows Phone 7,Isolatedstorage,我正在尝试删除在独立存储中创建的文件夹。 但我得到一个错误,即“路径必须是有效的文件名” 我创建的文件名是“a07292011//time.Schedule” 现在我想删除文件夹,我的代码是: myStore.DeleteDirectory(selectedFolderName1+“\\” 其中选择的FolderName1=a07292011// /// <summary> /// Method for deleting an isolated storage dir

我正在尝试删除在独立存储中创建的文件夹。 但我得到一个错误,即“路径必须是有效的文件名” 我创建的文件名是“a07292011//time.Schedule”

现在我想删除文件夹,我的代码是:

myStore.DeleteDirectory(selectedFolderName1+“\\”

其中选择的FolderName1=a07292011

//
    /// <summary>
    /// Method for deleting an isolated storage directory
    /// </summary>
    /// <param name="directoryName">Name of a directory to be deleted</param>
    public static void DeleteDirectory(string directoryName)
    {
        try
        {
            using (IsolatedStorageFile currentIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!string.IsNullOrEmpty(directoryName) && currentIsolatedStorage.DirectoryExists(directoryName))
                {
                    currentIsolatedStorage.DeleteDirectory(directoryName);
                }
            }
        }
        catch (Exception ex)
        {
            // do something with exception
        }
    }
///用于删除独立存储目录的方法 /// ///要删除的目录的名称 公共静态void DeleteDirectory(字符串directoryName) { 尝试 { 使用(IsolatedStorageFile currentIsolatedStorage=IsolatedStorageFile.GetUserStoreForApplication()) { 如果(!string.IsNullOrEmpty(directoryName)&¤tIsolatedStorage.DirectoryExists(directoryName)) { currentIsolatedStorage.DeleteDirectory(目录名); } } } 捕获(例外情况除外) { //例外地做某事 } }
在这里获取更多详细信息


您尝试删除的目录必须为空

public void DeleteDirectory(string directoryName) {
try {
    using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication()) {
        if (!string.IsNullOrEmpty(directoryName) && currentIsolatedStorage.DirectoryExists(directoryName)) {
            var fn = isoFile.GetFileNames(string.Concat(directoryName, "\\*"));
            if (fn.Length > 0)
                for (int i = 0; i < fn.Length; ++i)
                    isoFile.DeleteFile(string.Concat(directoryName, "\\", fn[i]));
            isoFile.DeleteDirectory(directoryName);
        }
    }
} catch (Exception ex) {
    //implement some error handling
}
}
public void DeleteDirectory(字符串目录名){
试一试{
使用(IsolatedStorageFile isoFile=IsolatedStorageFile.GetUserStoreForApplication()){
如果(!string.IsNullOrEmpty(directoryName)&¤tIsolatedStorage.DirectoryExists(directoryName)){
var fn=isoFile.getfilename(string.Concat(directoryName,“\\*”);
如果(fn.Length>0)
对于(int i=0;i
以下是我的代码,用于从独立存储中递归删除文件夹及其文件/子文件夹。它也适用于WindowsPhone8

public static void CleanAndDeleteDirectoryRecursive(string directory)
    {
        IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
        if (iso.DirectoryExists(directory))
        {
            string[] files = iso.GetFileNames(directory + @"/*");
            foreach (string file in files)
            {
                iso.DeleteFile(directory + @"/" + file);
                Debug.WriteLine("Deleted file: " + directory + @"/" + file);
            }

            string[] subDirectories = iso.GetDirectoryNames(directory + @"/*");
            foreach (string subDirectory in subDirectories)
            {
                CleanAndDeleteDirectoryRecursive(directory + @"/" + subDirectory);
            }

            iso.DeleteDirectory(directory);
            Debug.WriteLine("Deleted directory: " + directory);
        }
    }

我希望,不需要用目录名附加(+“\\”)。因为您要删除文件夹本身。它是currentIsolatedStorage.DirectoryExists(directoryName)返回true吗?检查该URL。目录必须为空才能删除。删除后的目录将无法恢复。感谢您的帮助。现在我明白为什么它已经不起作用了