I get an error (Server cannot set content type after HTTP headers have been sent.) on the following code (ContentType line). What should I change?
Do you need to set the content type? This solution should not be overlooked, because you may find your code to work perfectly without the need to explicitly define the content type for the type of response you are sending. So removing the following line should make the error go away, and may very well do so without introducing new problems (of course you'll want to test this against your scenario):
response.ContentType = "text/plain";