@@ -77,22 +77,48 @@ public override IAsyncAction CopyAndReplaceAsync(IStorageFile fileToReplace)
7777
7878 public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder )
7979 {
80- return File . MoveAsync ( destinationFolder ) ;
80+ return MoveAsync ( destinationFolder , Name , NameCollisionOption . FailIfExists ) ;
8181 }
8282
8383 public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder , string desiredNewName )
8484 {
85- return File . MoveAsync ( destinationFolder , desiredNewName ) ;
85+ return MoveAsync ( destinationFolder , desiredNewName , NameCollisionOption . FailIfExists ) ;
8686 }
8787
8888 public override IAsyncAction MoveAsync ( IStorageFolder destinationFolder , string desiredNewName , NameCollisionOption option )
8989 {
90- return File . MoveAsync ( destinationFolder , desiredNewName , option ) ;
90+ return AsyncInfo . Run ( async ( cancellationToken ) =>
91+ {
92+ var destFolder = destinationFolder . AsBaseStorageFolder ( ) ; // Avoid calling IStorageFolder method
93+ if ( destFolder is SystemStorageFolder sysFolder )
94+ {
95+ // File created by CreateFileAsync will get immediately deleted on MTP?! (#7206)
96+ await File . MoveAsync ( sysFolder . Folder , desiredNewName , option ) ;
97+ return ;
98+ }
99+ var destFile = await destFolder . CreateFileAsync ( desiredNewName , option . Convert ( ) ) ;
100+ using ( var inStream = await this . OpenStreamForReadAsync ( ) )
101+ using ( var outStream = await destFile . OpenStreamForWriteAsync ( ) )
102+ {
103+ await inStream . CopyToAsync ( outStream ) ;
104+ await outStream . FlushAsync ( ) ;
105+ }
106+ // Move unsupported, copy but do not delete original
107+ } ) ;
91108 }
92109
93110 public override IAsyncAction MoveAndReplaceAsync ( IStorageFile fileToReplace )
94111 {
95- return File . MoveAndReplaceAsync ( fileToReplace ) ;
112+ return AsyncInfo . Run ( async ( cancellationToken ) =>
113+ {
114+ using ( var inStream = await this . OpenStreamForReadAsync ( ) )
115+ using ( var outStream = await fileToReplace . OpenStreamForWriteAsync ( ) )
116+ {
117+ await inStream . CopyToAsync ( outStream ) ;
118+ await outStream . FlushAsync ( ) ;
119+ }
120+ // Move unsupported, copy but do not delete original
121+ } ) ;
96122 }
97123
98124 public override string ContentType => File . ContentType ;
0 commit comments