uwp - How to copy file to another folder and remove the file -


i used below code , error message:

{"error hresult e_fail has been returned call com component."}

if use this, work provided there no similiar file exits.

await targetfile.copyasync(folder, strfilenm);

public static async void copythefile(storagefolder subfdl, string strfilenm)         {             string strpath = "c:\\users\\xyzuser\\documents\\mystuffbu";              storagefolder folder = await storagefolder.getfolderfrompathasync(strpath);             var targetfile = await subfdl.getfileasync(strfilenm);              await targetfile.copyandreplaceasync(targetfile);                         await targetfile.deleteasync();               } 

how this:

copy file current folder (in c:) , folder (in c:) there similar filename exits later, remove file in current folder

thanks.

you trying replace file copy of line:

await targetfile.copyandreplaceasync(targetfile);  

see documentation of copyandreplaceasync.

you should use moveasync or 1 of it's overrides. way won't have call deleteasync neither, since file moved.


Comments