Chapter 12: File and Registry Operations

 
Chapter 12 - File and Registry Operations
bySimon Robinsonet al.
Wrox Press 2002
  

Overview

In this chapter, we will examine how to perform tasks involving reading from and writing to files and the system registry in C#. In particular, we are going to cover:

  • Exploring the directory structure, finding out what files and folders are present and checking their properties

  • Moving, copying, and deleting files and folders

  • Reading and writing text in files

  • Reading and writing keys in the Registry

Microsoft has provided very intuitive object models covering these areas, and during this chapter we will show you how to use .NET base classes to perform the tasks mentioned above. For the case of file system operations, the relevant classes are almost all found in the System.IO namespace, while registry operations are dealt with by a couple of classes in the Microsoft.Win32 namespace.

The .NET base classes also include a number of classes and interfaces in the System.Runtime.Serialization namespace that are concerned with serialization that is the process of converting some data (for example, the contents of a document) into a stream of bytes for storage somewhere. We won't be focusing on these classes in this chapter; we will be focusing on the classes that are available to give you direct access to files.

Note that although security affects all areas, security is particularly important when modifying files or registry entries. The whole area of security is covered separately in Chapter 23. In this chapter, however, we will simply assume that you have sufficient access rights to run all the examples that modify files or registry entries, which should be the case if you are running from an account with administrator privileges.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net