Since echo
appends a newline, you can issue multiple echo commands.
server.ConnectionContext.ExecuteNonQuery(
"xp_cmdshell 'ECHO line1 >> " + destinationPathFormat + "'");
server.ConnectionContext.ExecuteNonQuery(
"xp_cmdshell 'ECHO line2 >> " + destinationPathFormat + "'");
server.ConnectionContext.ExecuteNonQuery(
"xp_cmdshell 'ECHO line3 >> " + destinationPathFormat + "'");
You're already using >>
, which appends to a file, instead of >
, which creates a file.