c# - BackgroundTransfer cannot move files -
i having problem downloading files using background transfer. after completion of download when moving file, gives exception operation not permitted
void addtransferrequest(string filename) { if (string.isnullorempty(filename)) return; string filepathtodownload = string.empty; filepathtodownload = activereciter.downloadurl; filepathtodownload += filename; uri transferuri = new uri(uri.escapeuristring(filepathtodownload), urikind.relativeorabsolute); backgroundtransferrequest transferrequest = new backgroundtransferrequest(transferuri); transferrequest.method = "get"; transferrequest.transferpreferences = transferpreferences.allowbattery; uri downloaduri = new uri(datasource.tempdownloadlocation + filename, urikind.relativeorabsolute); transferrequest.downloadlocation = downloaduri; transferrequest.tag = filename; transferrequest.transferstatuschanged += new eventhandler<backgroundtransfereventargs> (transfer_transferstatuschanged); transferrequest.transferprogresschanged += new eventhandler<backgroundtransfereventargs>(transfer_transferprogresschanged); try { backgroundtransferservice.add(transferrequest); chapterfilenames.dequeue(); } catch (invalidoperationexception) { } catch (exception) { } } void transfer_transferstatuschanged(object sender, backgroundtransfereventargs e) { processtransfer(e.request); } void transfer_transferprogresschanged(object sender, backgroundtransfereventargs e) { } private void processtransfer(backgroundtransferrequest transfer) { switch (transfer.transferstatus) { case transferstatus.completed: if (transfer.statuscode == 200 || transfer.statuscode == 206) { using (isolatedstoragefile isostore = isolatedstoragefile.getuserstoreforapplication()) { try { string filename = transfer.tag; string folderpath = string.format(@"{0}{1}\{2}\", datasource.downloadlocation, activereciter.reciterid, chapter.chapterid); string filefullpath = folderpath + filename; if (!isostore.directoryexists(path.getdirectoryname(folderpath))) isostore.createdirectory(path.getdirectoryname(folderpath)); if (isostore.fileexists(filefullpath)) isostore.deletefile(filefullpath); isostore.movefile(transfer.downloadlocation.originalstring, filefullpath); //excpetion thrown here removetransferrequest(transfer.requestid); } catch (exception ex) { messagebox.show("error occured: " + ex.message + transfer.tag, "error", messageboxbutton.ok); return; } } } break; } }
when moving file, throws exception, don't know wrong moving (this happens on of files not files).
from msdn page, under file system restrictions
section:
you can create additional directory structure choose underneath root “/shared/transfers” directory, , can copy or move files after transfer complete ensure background transfer service not modify files, attempting initiate transfer using path outside of “/shared/transfers” directory throw exception.
make sure not trying move file outside /shared/transfers
folder.
Comments
Post a Comment