Zebra0.com

csharp filesC# Windows Forms Programming

C# Windows Forms Programming

Learn C# (C sharp) in FREE step-by-step lessons.

Files in C#

There are two types of files that can be created: text files and binary files.

Text files have variable length records. (One line of text may have 20 characters, the next line 5, etc.)
A text file must be read sequentially: line 1, then line 2, etc.
Text files are also called sequential files. We will learn about text files in this lesson.

Each record in a binary file must be exactly the same size.
Because all of the records are the same length, a binary file can be read either sequentially or randomly.
Suppose each record has exactly 20 bytes.
The location of the first record in the file is always known.
The second record begins 20 bytes past that.
The fifth record begins 80 bytes past the beginning of the file.
If the position where each record starts can be calculated, then we can read the Nth record without reading all of the records before it.
Binary files are also called Random Access files.

In this lesson we will also look at some commands for working with files and folders in C#.

Please study the material at each of the links below.

  1. Microsoft Reference: Microsoft Reference:: C# Files, The Directory Class

  2. Filter: The Filter is used with the file dialog to specify the types of files to be selected.

  3. Font: Font is a property that can be selected for controls and for drawing.

  4. Font Dialog: The Font Dialog is one of the common dialog controls for selecting fonts and font properties

  5. Clipboard program Clipboard program: Build the form
    /csharp/videos/csharp-clipboard1.mp4
  6. Clipboard program Part 2 Clipboard program Part 2: Code: read file into list box, copy from listbox to clipboard
    /csharp/videos/csharp-clipboard2.mp4
  7. Read a file line by line: Read in a CSV (comma separated values) file

  8. Write to text file: Write the contents of a combo box to a text file

  9. Reformat as XML: Read a text file and write as XML format.

  10. Directory: The Directory command is used to retrieve an array of all the files in a directory.

  11. Parameters for the Directory Method: Specify file type or pattern

GlossaryGlossary for files lesson
Full Glossary