13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

372<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>Key Skills & Concepts●●●●●System.IO namespaceWriting text filesAppending text filesReading text filesDisplaying directories and filesSome web sites you build may need very little stored data or data access. As you have seenin the previous chapters examining ADO.<strong>NET</strong>, building databases and tables requiresseveral steps to set up just what you need. Sometimes, though, all you need is a simple textfile to store text for basic data entry and retrieval on the Web. Using no database, table, orspecial connection protocol, you can work with text files to store simple data and access thatstored text using <strong>ASP</strong>.<strong>NET</strong> and C#. This chapter examines this relatively simple file writingand reading process for those applications where you need just a little data. Likewise, if youor your client does not have access to a database using files, you can create a rudimentary“pauper’s database”!Writing FilesAt the outset you need to be aware that if you have a relatively <strong>com</strong>plex set of data anddata types and expect high-volume usage, you should use a database and tables. However,solely for simple, text-only projects, you can effectively use plain-text files for writingdata and retrieving it. Compared with setting up a database and tables and writing data todifferent fields, creating, writing to, and appending text files is a simple procedure.Using StreamWriterThe first file-writing web site shows how to use the StreamWriter class to create atext file and then store data in that file. A StreamWriter instance defaults to UnicodeTransformation Format-8 (UTF-8) that encodes in the Unicode standard. It is backwardly<strong>com</strong>patible to ASCII format so that it can handle ASCII data sets. At this writing, UTF-8is be<strong>com</strong>ing the default text standard, so it should work well with just about any system.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!