question

ahmedsalah-1628 avatar image
0 Votes"
ahmedsalah-1628 asked YiyiYou-MSFT edited

Exception The target file is a directory, not a file. on file.copy

I work on asp.net core 3.1 web api

I get exception error as below :

Exception The target file is a directory, not a file. on file.copy

this lines generated exception

System.IO.File.Copy(OutputfilePath, Path.Combine(exportDirectory, fileName), true);

 Path.Combine(exportDirectory, fileName) is : “\\192.168.2.7\\ImportExport\\2\\Export\DeliveryGeneration_Input (69)-af650a86-ea90-40c1-86da-74f4b2c8132e.xlsx”

   

 OutputfilePath is  : “\\192.168.2.7\\ImportExport\\2\\Export\DeliveryGenerationOutput.xlsx”

two files can access and open it when i open on fil explorer but issue

as error above

so How to solve this issue please ?

dotnet-csharpdotnet-aspnet-core-webapi
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe the paths should be:

  • \\192.168.2.7\ImportExport\2\Export\. . .

which in case of C# strings are:

  • "\\\\192.168.2.7\\ImportExport\\2\\Export\\. . .".



0 Votes 0 ·

so how to change on code
also i get path from code and put it on file explorer it open
so what is issue

0 Votes 0 ·

can we more clear please

both destination and source is files not directory

GetFilesDownload variable is

\\\\192.168.2.7\\ImportExport\\testImporter
string Month = DateTime.Now.Month.ToString();
string exportDirectory = GetFilesDownload + "\\" + Month;


var OutputfilePath = System.IO.Path.Combine( GetFilesDownload, "DeliveryGeneration_Output.xlsx");

System.IO.File.Copy(OutputfilePath, Path.Combine(exportDirectory, fileName), true);

0 Votes 0 ·

0 Answers