Archive for February, 2008

CHAPTER 16 (Photoshop web design) THE SYSTEM.IO NAMESPACE 529 static

Wednesday, February 20th, 2008

CHAPTER 16 THE SYSTEM.IO NAMESPACE 529 static void Main(string[] args) { … FileInfo f6 = new FileInfo(@”C:Test5.txt”); StreamWriter swriter = f6.CreateText(); // Use the StreamWriter object… swriter.Close(); FileInfo f7 = new FileInfo(@”C:FinalTest.txt”); StreamWriter swriterAppend = f7.AppendText(); // Use the StreamWriter object… swriterAppend.Close(); } As you would guess, the StreamWriter type provides a way to write character data to the underlying file. Working with the File Type The File type provides functionality almost identical to that of the FileInfo type, using a number of static members. Like FileInfo, File supplies AppendText(), Create(), CreateText(), Open(), OpenRead(), OpenWrite(), and OpenText() methods. In fact, in many cases, the File and FileStream types may be used interchangeably. To illustrate, each of the previous FileStream examples can be simplified by using the File type instead: static void Main(string[] args) { // Obtain FileStream object via File.Create(). FileStream fs = File.Create(@”C:Test.dat”); fs.Close(); // Obtain FileStream object via File.Open(). FileStream fs2 = File.Open(@”C:Test2.dat”, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); fs2.Close(); // Get a FileStream object with read-only permissions. FileStream readOnlyStream = File.OpenRead(@”Test3.dat”); readOnlyStream.Close(); // Get a FileStream object with write-only permissions. FileStream writeOnlyStream = File.OpenWrite(@”Test4.dat”); writeOnlyStream.Close(); // Get a StreamReader object. StreamReader sreader = File.OpenText(@”C:boot.ini”); sreader.Close();
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

The FileInfo.OpenRead() and FileInfo.OpenWrite() Methods While the FileInfo.Open()

Tuesday, February 19th, 2008

The FileInfo.OpenRead() and FileInfo.OpenWrite() Methods While the FileInfo.Open() method allows you to obtain a file handle in a very flexible manner, the FileInfo class also provides members named OpenRead() and OpenWrite(). As you might imagine, these methods return a properly configured read-only or write-only FileStream type, without the need to supply various enumeration values. Like FileInfo.Create() and FileInfo.Open(), OpenRead() and OpenWrite() return a FileStream object: static void Main(string[] args) { … // Get a FileStream object with read-only permissions. FileInfo f3 = new FileInfo(@”C:Test3.dat”); FileStream readOnlyStream = f3.OpenRead(); // Use the FileStream object… readOnlyStream.Close(); // Now get a FileStream object with write-only permissions. FileInfo f4 = new FileInfo(@”C: Test4.dat”); FileStream writeOnlyStream = f4.OpenWrite(); // Use the FileStream object… writeOnlyStream.Close(); } The FileInfo.OpenText() Method Another open-centric member of the FileInfo type is OpenText(). Unlike Create(), Open(), OpenRead(), and OpenWrite(), the OpenText() method returns an instance of the StreamReader type, rather than a FileStream type: static void Main(string[] args) { … // Get a StreamReader object. FileInfo f5 = new FileInfo(@”C:boot.ini”); StreamReader sreader = f5.OpenText(); // Use the StreamReader object… sreader.Close(); } As you will see shortly, the StreamReader type provides a way to read character data from the underlying file. The FileInfo.CreateText() and FileInfo.AppendText() Methods The final two methods of interest at this point are CreateText() and AppendText(), both of which return a StreamWriter reference, as shown here: CHAPTER 16 528 THE SYSTEM.IO NAMESPACE
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Web hosting packages - CHAPTER 16 THE SYSTEM.IO NAMESPACE 527 The

Tuesday, February 19th, 2008

CHAPTER 16 THE SYSTEM.IO NAMESPACE 527 The FileInfo.Open() Method You can use the FileInfo.Open() method to open existing files as well as create new files with far more precision than FileInfo.Create(). Once the call to Open() completes, you are returned a FileStream object. Ponder the following logic: static void Main(string[] args) { … // Make a new file via FileInfo.Open(). FileInfo f2 = new FileInfo(@”C:Test2.dat”); FileStream fs2 = f2.Open( FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); // Use the FileStream object… // Close down file stream. fs2.Close(); } This version of the overloaded Open() method requires three parameters. The first parameter specifies the general flavor of the I/O request (e.g., make a new file, open an existing file, append to a file, etc.), which is specified using the FileMode enumeration: public enum FileMode { // Specifies that the operating system should create a new file. // If the file already exists, a System.IO.IOException is thrown. CreateNew, // Specifies that the operating system should create a new file. // If the file already exists, it will be overwritten. Create, Open, // Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. OpenOrCreate, Truncate, Append } The second parameter, a value from the FileAccess enumeration, is used to determine the read/write behavior of the underlying stream: public enum FileAccess { Read, Write, ReadWrite } Finally, you have the third parameter, FileShare, which specifies how the file is to be shared among other file handlers. Here are the core names: public enum FileShare { None, Read, Write, ReadWrite }
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

Florida web design - Table 16-4. FileInfo Core Members Member Meaning in

Monday, February 18th, 2008

Table 16-4. FileInfo Core Members Member Meaning in Life AppendText() Creates a StreamWriter type (described later) that appends text to a file CopyTo() Copies an existing file to a new file Create() Creates a new file and returns a FileStream type (described later) to interact with the newly created file CreateText() Creates a StreamWriter type that writes a new text file Delete() Deletes the file to which a FileInfo instance is bound Directory Gets an instance of the parent directory DirectoryName Gets the full path to the parent directory Length Gets the size of the current file or directory MoveTo() Moves a specified file to a new location, providing the option to specify a new filename Name Gets the name of the file Open() Opens a file with various read/write and sharing privileges OpenRead() Creates a read-only FileStream OpenText() Creates a StreamReader type (described later) that reads from an existing text file OpenWrite() Creates a write-only FileStream type It is important to understand that amajority of the members of the FileInfo class return a specific I/O-centric object (FileStream, StreamWriter, and so forth) that allows you to begin reading and writing data to (or reading from) the associated file in a variety of formats. You will check out these types in just a moment, but until then, let s examine various ways to obtain a file handle using the FileInfo class type. The FileInfo.Create() Method The first way you can create a file handle is to make use of the FileInfo.Create() method: public class Program { static void Main(string[] args) { // Make a new file on the C drive. FileInfo f = new FileInfo(@”C:Test.dat”); FileStream fs = f.Create(); // Use the FileStream object… // Close down file stream. fs.Close(); } } Notice that the FileInfo.Create() method returns a FileStream type, which exposes synchronous and asynchronous write/read operations to/from the underlying file. Do know that the FileStream object returned by FileInfo.Create() grants full read/write access to all users. CHAPTER 16 526 THE SYSTEM.IO NAMESPACE
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Affordable web hosting - CHAPTER 16 THE SYSTEM.IO NAMESPACE 525 //

Sunday, February 17th, 2008

CHAPTER 16 THE SYSTEM.IO NAMESPACE 525 // Check to see if the drive is mounted. if (d.IsReady) { Console.WriteLine(”Free space: {0}”, d.TotalFreeSpace); Console.WriteLine(”Format: {0}”, d.DriveFormat); Console.WriteLine(”Label: {0}n”, d.VolumeLabel); } } Console.ReadLine(); } } Figure 16-5 shows the output based on my current machine. Figure 16-5. Gather drive details via DriveInfo At this point, you have investigated some core behaviors of the Directory, DirectoryInfo, and DriveInfo classes. Next, you ll learn how to create, open, close, and destroy the files that populate a given directory. Source Code The DriveTypeApp project is located under the Chapter 16 subdirectory. Working with the FileInfo Class As shown in the MyDirectoryApp example, the FileInfo class allows you to obtain details regarding existing files on your hard drive (time created, size, file attributes, and so forth) and aids in the creation, copying, moving, and destruction of files. In addition to the set of functionality inherited by FileSystemInfo are some core members unique to the FileInfo class, which are described in Table 16-4.
We recommend high quality webhost to host and run your jsp application: christian web host services.

Domain and web hosting - class Program { static void Main(string[] args) {

Saturday, February 16th, 2008

class Program { static void Main(string[] args) { … // List all drives on current computer. string[] drives = Directory.GetLogicalDrives(); Console.WriteLine(”Here are your drives:”); foreach(string s in drives) Console.WriteLine(” >{0} “, s); // Delete what was created. Console.WriteLine(”Press Enter to delete directories”); Console.ReadLine(); try { Directory.Delete(@”C:WindowsMyFoo”); // The second parameter specifies if you // wish to destroy any subdirectories. Directory.Delete(@”C:WindowsMyBar”, true); } catch(IOException e) { Console.WriteLine(e.Message); } } } Source Code The MyDirectoryApp project is located under the Chapter 16 subdirectory. Working with the DriveInfo Class Type As of .NET 2.0, the System.IO namespace provides a class named DriveInfo. Like Directory. GetLogicalDrives(), the static DriveInfo.GetDrives() method allows you to discover the names of a machine s drives. Unlike Directory.GetLogicalDrives(), however, DriveInfo provides numerous other details (such as the drive type, available free space, volume label, and whatnot). Consider the following sample code: class Program { static void Main(string[] args) { Console.WriteLine(”***** Fun with DriveInfo *****n”); // Get info regarding all drives. DriveInfo[] myDrives = DriveInfo.GetDrives(); // Now print drive stats. foreach(DriveInfo d in myDrives) { Console.WriteLine(”Name: {0}”, d.Name); Console.WriteLine(”Type: {0}”, d.DriveType); CHAPTER 16 524 THE SYSTEM.IO NAMESPACE
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

CHAPTER 16 THE SYSTEM.IO (Web site design and hosting) NAMESPACE 523 class

Friday, February 15th, 2008

CHAPTER 16 THE SYSTEM.IO NAMESPACE 523 class Program { static void Main(string[] args) { Console.WriteLine(”***** Fun with Directory(Info) *****n”); DirectoryInfo dir = new DirectoryInfo(@”C:Windows”); … // Create MyFoo off initial directory. dir.CreateSubdirectory(”MyFoo”); // Create MyBarMyQaaz off initial directory. dir.CreateSubdirectory(@”MyBarMyQaaz”); } } If you examine your Windows directory using Windows Explorer, you will see that the new subdirectories are present and accounted for (see Figure 16-4). Figure 16-4. Creating subdirectories Although you are not required to capture the return value of the CreateSubdirectory() method, be aware that a DirectoryInfo type representing the newly created item is passed back on successful execution: // CreateSubdirectory() returns a DirectoryInfo item representing the new item. DirectoryInfo d = dir.CreateSubdirectory(”MyFoo”); Console.WriteLine(”Created: {0} “, d.FullName); d = dir. CreateSubdirectory(@”MyBarMyQaaz”); Console.WriteLine(”Created: {0} “, d.FullName); Working with the Directory Type Now that you have seen the DirectoryInfo type in action, you can learn about the Directory type. For the most part, the members of Directory mimic the functionality provided by the instance-level members defined by DirectoryInfo. Recall, however, that the members of Directory typically return string types rather than strongly typed FileInfo/DirectoryInfo types. To illustrate some functionality of the Directory type, the final iteration of this example displays the names of all drives mapped to the current computer (via the Directory.GetLogicalDrives() method) and uses the static Directory.Delete() method to remove the MyFoo and MyBarMyQaaz subdirectories previously created:
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

class Program { static (Jetty web server) void Main(string[] args) {

Thursday, February 14th, 2008

class Program { static void Main(string[] args) { Console.WriteLine(”***** Fun with Directory(Info) *****n”); DirectoryInfo dir = new DirectoryInfo(@”C:Windows”); … // Get all files with a *.bmp extension. FileInfo[] bitmapFiles = dir.GetFiles(”*.bmp”); // How many were found? Console.WriteLine(”Found {0} *.bmp filesn”, bitmapFiles.Length); // Now print out info for each file. foreach (FileInfo f in bitmapFiles) { Console.WriteLine(”***************************n”); Console.WriteLine(”File name: {0} “, f.Name); Console.WriteLine(”File size: {0} “, f.Length); Console.WriteLine(”Creation: {0} “, f.CreationTime); Console.WriteLine(”Attributes: {0} “, f.Attributes); Console.WriteLine(”***************************n”); } } } Once you run the application, you see a listing something like that shown in Figure 16-3. (Your bitmaps may vary!) CHAPTER 16 522 THE SYSTEM.IO NAMESPACE Figure 16-3. Bitmap file information Creating Subdirectories with the DirectoryInfo Type You can programmatically extend a directory structure using the DirectoryInfo.CreateSubdirectory() method. This method can create a single subdirectory, as well as multiple nested subdirectories, in a single function call. To illustrate, here is a block of code that extends the directory structure of C:Windows with some custom subdirectories:
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Affordable web hosting - CHAPTER 16 THE SYSTEM.IO NAMESPACE 521 The

Wednesday, February 13th, 2008

CHAPTER 16 THE SYSTEM.IO NAMESPACE 521 The FileAttributes Enumeration The Attributes property exposed by FileSystemInfo provides various traits for the current directory or file, all of which are represented by the FileAttributes enumeration (enum). While the names of this enum are fairly self-describing, some of the less obvious names are documented here (consult the .NET Framework 2.0 SDK documentation for full details): public enum FileAttributes { ReadOnly, Hidden, // The file is part of the operating system or is used // exclusively by the operating system System, Directory, Archive, // This name is reserved for future use. Device, // The file is ‘normal’ as it has no other attributes set. Normal, Temporary, // Sparse files are typically large files whose data are mostly zeros. SparseFile, // A block of user-defined data associated with a file or a directory ReparsePoint, Compressed, Offline, // The file will not be indexed by the operating system’s // content indexing service. NotContentIndexed, Encrypted } Enumerating Files with the DirectoryInfo Type In addition to obtaining basic details of an existing directory, you can extend the current example to use some methods of the DirectoryInfo type. First, let s leverage the GetFiles() method to obtain information about all *.bmp files located under the C:Windows directory. This method returns an array of FileInfo types, each of which exposes details of a particular file (full details of the FileInfo type are explored later in this chapter): Figure 16-2. Information about your Windows directory
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

CHAPTER 16 520 THE SYSTEM.IO NAMESPACE Table (Web design)

Tuesday, February 12th, 2008

CHAPTER 16 520 THE SYSTEM.IO NAMESPACE Table 16-3. (Continued) Members Meaning in Life GetFiles() Retrieves an array of FileInfo types that represent a set of files in the given directory MoveTo() Moves a directory and its contents to a new path Parent Retrieves the parent directory of the specified path Root Gets the root portion of a path You begin working with the DirectoryInfo type by specifying a particular directory path as a constructor parameter. If you want to obtain access to the current application directory (i.e., the directory of the executing application), use the “.” notation. Here are some examples: // Bind to the current application directory. DirectoryInfo dir1 = new DirectoryInfo(”.”); // Bind to C:Windows, // using a verbatim string. DirectoryInfo dir2 = new DirectoryInfo(@”C:Windows”); In the second example, you are making the assumption that the path passed into the constructor (C:Windows) already exists on the physical machine. However, if you attempt to interact with a nonexistent directory, a System.IO.DirectoryNotFoundException is thrown. Thus, if you specify a directory that is not yet created, you will need to call the Create() method before proceeding: // Bind to a nonexistent directory, then create it. DirectoryInfo dir3 = new DirectoryInfo(@”C:WindowsTesting”); dir3.Create(); Once you have created a DirectoryInfo object, you can investigate the underlying directory contents using any of the properties inherited from FileSystemInfo. To illustrate, the following class creates a new DirectoryInfo object mapped to C:Windows (adjust your path if need be) and displays a number of interesting statistics (see Figure 16-2 for output): class Program { static void Main(string[] args) { Console.WriteLine(”***** Fun with Directory(Info) *****n”); DirectoryInfo dir = new DirectoryInfo(@”C:Windows”); // Dump directory information. Console.WriteLine(”***** Directory Info *****”); Console.WriteLine(”FullName: {0} “, dir.FullName); Console.WriteLine(”Name: {0} “, dir.Name); Console.WriteLine(”Parent: {0} “, dir.Parent); Console.WriteLine(”Creation: {0} “, dir.CreationTime); Console.WriteLine(”Attributes: {0} “, dir.Attributes); Console.WriteLine(”Root: {0} “, dir.Root); Console.WriteLine(”**************************n”); } }
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.