c# - Path.Combine and File.Move with dot in file path -
considering below foreach loop:
foreach (fileinfo fileinfo in files) { string filename = fileinfo.tostring(); filename = filename.split('_')[0]; // file suffix string sqlstring = "select 'company-plc.' + ftpuser dbo.control brand = @filename;"; sqlconnection connection = new sqlconnection(conn); sqlcommand cmd = new sqlcommand(sqlstring, connection); cmd.parameters.addwithvalue("@filename", filename); connection.open(); sqldatareader reader = cmd.executereader(); while (reader.read()) { string destinationsuffix = reader[0].tostring(); string fullpath = path.combine(destinationpath,destinationsuffix); fullpath = path.combine(fullpath, fileinfo.fullname); file.move(fileinfo.fullname,fullpath); } reader.close(); }
current fileinfo location: \\server\directory
original value of destinationpath
= \\server\folder\folder
after sql query, destinationsuffix
= company-plc.test
the file being moved fileinfo
called test.csv
.
current outcome:
file not moved, file .test
extension created i.e.
\\server\directory\company-plc.test
desired outcome:
\\server\folder\folder\company-plc.test\test.csv
can see path.combine
erring?
check documentation of path.combine - find if second parameter consists of full pathname - returned. try using fileinfo.name instead.
fullpath = path.combine(fullpath, fileinfo.name);
https://msdn.microsoft.com/en-us/library/fyy7a5kt(v=vs.110).aspx
Comments
Post a Comment