locked
Is there any method available to move directory in Windows Store apps same as IsolatedStorageFile.MoveDirectory windows phone platform. RRS feed

  • Frage

  • Is there any method available to move directory from one location to another in Windows Store apps same as IsolatedStorageFile.MoveDirectory windows phone platform.

    Ravindra

    Montag, 10. Februar 2014 10:00

Antworten

  • no there isnt;

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefolder.aspx

    you will need to write it manually


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Als Antwort markiert Anne Jing Montag, 17. Februar 2014 03:43
    Montag, 10. Februar 2014 10:44
  • here you are:

    public static class StorageFolderExtensions
        {
            public static async Task MoveFolderASync(this StorageFolder folder, StorageFolder target)
            {
                StorageFolder createdFolder = await target.CreateFolderAsync(folder.Name, CreationCollisionOption.FailIfExists).AsTask().ConfigureAwait(false);
                IReadOnlyList<StorageFolder> subfolders = await folder.GetFoldersAsync().AsTask().ConfigureAwait(false);
                foreach (StorageFolder subfolder in subfolders)
                {
                    await MoveFolderASync(subfolder, createdFolder);
                    await subfolder.DeleteAsync();
                }
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync().AsTask().ConfigureAwait(false);
                foreach(StorageFile file in files)
                {
                    await file.CopyAsync(createdFolder);
                    await file.DeleteAsync();
                }
                await folder.DeleteAsync();
            }
        }
    
        public class MyClass    
        {
            public async Task DemoMove()
            {
                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Demo Content");
                await folder.CreateFileAsync("My File");
                await folder.CreateFolderAsync("My SubFolder");
    
    
                var targetFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("target");
                await folder.MoveFolderASync(targetFolder);
            }
        }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Als Antwort markiert Raindra Verma Mittwoch, 26. März 2014 11:27
    Mittwoch, 19. Februar 2014 13:21

Alle Antworten

  • no there isnt;

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefolder.aspx

    you will need to write it manually


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Als Antwort markiert Anne Jing Montag, 17. Februar 2014 03:43
    Montag, 10. Februar 2014 10:44
  • Can you provide me some code snippet.

    Ravindra

    Mittwoch, 19. Februar 2014 12:56
  • here you are:

    public static class StorageFolderExtensions
        {
            public static async Task MoveFolderASync(this StorageFolder folder, StorageFolder target)
            {
                StorageFolder createdFolder = await target.CreateFolderAsync(folder.Name, CreationCollisionOption.FailIfExists).AsTask().ConfigureAwait(false);
                IReadOnlyList<StorageFolder> subfolders = await folder.GetFoldersAsync().AsTask().ConfigureAwait(false);
                foreach (StorageFolder subfolder in subfolders)
                {
                    await MoveFolderASync(subfolder, createdFolder);
                    await subfolder.DeleteAsync();
                }
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync().AsTask().ConfigureAwait(false);
                foreach(StorageFile file in files)
                {
                    await file.CopyAsync(createdFolder);
                    await file.DeleteAsync();
                }
                await folder.DeleteAsync();
            }
        }
    
        public class MyClass    
        {
            public async Task DemoMove()
            {
                var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Demo Content");
                await folder.CreateFileAsync("My File");
                await folder.CreateFolderAsync("My SubFolder");
    
    
                var targetFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("target");
                await folder.MoveFolderASync(targetFolder);
            }
        }


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    • Als Antwort markiert Raindra Verma Mittwoch, 26. März 2014 11:27
    Mittwoch, 19. Februar 2014 13:21