c# - How to move image files from one folder to another -
i looking way move file 1 directory using c#. have forms application have user select file using file chooser , upon clicking "set background" button have file transferred location specified within application.
upon trying answer provided @vulgarbinary getting following exception:
system.io.ioexception: cannot create file when file exists.
you need ensure program has appropriate permissions write files but:
if (file.exists(sourcepath)) { file.move(sourcepath, destinationpath); }
this should work wanting do.
example:
var sourcepath = "c:\users\someuser\pictures\vulgarbinary.jpg"; var destinationpath = "c:\whatever\path\you\want\vulgarbinary.jpg";
edit 1
given comments below answer running problem file creating exists. if replace can simple do:
if (file.exists(sourcepath)) { if(file.exists(destinationpath)) file.delete(destinationpath); file.move(sourcepath, destinationpath); }
if don't care output file's name , want write can like:
var outputdirectory = "c:\\whatever\\path\\you\\want\\"; if (file.exists(sourcepath)) { file.move(sourcepath, outputdirectory + guid.newguid().tostring() + ".jpg"); }
the latter copy file (all-be-it different name). first solution replace file same name new file.
cheers!
Comments
Post a Comment