Writing string content to a file

This code describes how to write content to a file

StringBuilder stringData = new StringBuilder();
stringData= "Any String Content.It may be custom built XML String/Web method Call etc..,";
FileStream fs = new FileStream("Complete File Path", FileMode.Create);
byte[] buffer = new byte[stringData.Length];
for (int i = 0; i < stringData.Length; i++)
buffer[i] = (byte)stringData[i];
fs.Write(buffer, 0, buffer.Length);


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: