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

    Question

  • 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

    Monday, February 10, 2014 10:00 AM

Answers

  • 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#

    Monday, February 10, 2014 10:44 AM
  • 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#

    • Marked as answer by Raindra Verma Wednesday, March 26, 2014 11:27 AM
    Wednesday, February 19, 2014 1:21 PM

All replies

  • 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#

    Monday, February 10, 2014 10:44 AM
  • Can you provide me some code snippet.

    Ravindra

    Wednesday, February 19, 2014 12:56 PM
  • 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#

    • Marked as answer by Raindra Verma Wednesday, March 26, 2014 11:27 AM
    Wednesday, February 19, 2014 1:21 PM