Simple problem. See if you can spot the difference: xmloutput.FileName = @"c\projects\text.xml"; xmloutput.FileName = @"c:\projects\text.xml"; In essence the path you specified is not what you had intended. You meant to specify an absolute path. The compiler didn't detect the drive (c:) and treats the whole thing as path relative to wherever the application is being run from. In your case the bin\Debug.