0

I have a web api written with c#, which is supposed to create a report based on some input from a client. My initial thought was to create this .txt file on the server, and then supply it to the client. But this is an api to be used by several concurrent users. So I have to create a file with unique name, write to it, send it and delete it. Which seems unnecessary. Is it better to just store this information in memory before I send it? How can I keep the same formatting as I would using write to file with string.format. Is it enough to just use a stringbuilder?

Balle
  • 71
  • 8
  • Why can't you just write it to the output stream as you generate it? – ProgrammingLlama May 19 '17 at 10:43
  • I'm new to this, so I just don't know the possibilities. Like how to use an output stream – Balle May 19 '17 at 10:46
  • Why don't you use a `MemoryStream` instead of create and delete de file? And the title of your question *Send file from webapi or use stringbuilder?* is confusing, there's no relation between `Webapi` and `StringBuider`. A title like * StringBuilder or String.Format* would be more understandable – Ricardo Pontual May 19 '17 at 10:49
  • See [here](http://stackoverflow.com/questions/16168683/webapi-streamcontent-vs-pushstreamcontent) – ProgrammingLlama May 19 '17 at 10:51

0 Answers0