-1

I've tried to copy the mainlist xml file to bin\Debug folder. But It throws exception. I've passed argument in console application like "C:\Users\gio.frog\Desktop\mainlist.xml" and used file.copy method like follows:

File.Copy(args[0], AppDomain.CurrentDomain.BaseDirectory + "sublist.xml",true);

I've seen some same exception example in stackoverflow but can't get the correct reason. How to copy to bin/debug folder.?

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Gio Frog
  • 89
  • 1
  • 7

1 Answers1

2

The AppDomain.CurrentDomain.BaseDirectory returns path without \ at the end. When you combine it with a trying it will concatenate with directory name.

E.g. "c:\projects\Debug\bin" + "sublist.xml" will result in "c:\projects\Debug\binsublist.xml"

Use

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "sublist.xml");
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
vendettamit
  • 14,315
  • 2
  • 32
  • 54