According to Microsoft's documentation I can attach files to a manual test case, but they have nothing for automated tests.
Here's a snippet of code you can use to do what you want: http://vivekbansod.blogspot.com/2013/06/add-attachment-to-test-case-result.html
I'm assuming you're using MSTest, and if that's the case you can use
TestContext.AddResultFile() (MSDN Documentation). This won't attach files to the test case work item though, it'll only attach files to the test execution result.