Resources » Code Snippets » C# Syntax

Writing string content to a file


Posted Date: 09-Oct-2008  Last Updated:   Category: C# Syntax    
Author: Member Level: Bronze    Points: 7



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);
fs.Close();


Did you like this resource? Share it with your friends and show your love!

Responses to "Writing string content to a file"
Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Gopi A
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India