There are multiple ways you can create files in C# and FileInfo class is one of them. The FileInfo class in the .NET Framework class library provides static methods for creating, reading, copying, moving, and deleting files using the FileStream objects.
The FileInfo class is defined in the System.IO namespace. You must import this namespace before using the class.
- using System.IO;
A FileInfo object is created using the default constructor that takes a string as a file name with a full path.
- string fileName = @"C:\Temp\MaheshTXFI.txt";
- FileInfo fi = new FileInfo(fileName);
Here is a complete sample that not only creates a file but also reads a file attributes such as file creation time, its size, last updated, last accessed, and last write times.
- // Full file name
- string fileName = @"C:\Temp\MaheshTXFI.txt";
- FileInfo fi = new FileInfo(fileName);
- // Create a new file
- using (FileStream fs = fi.Create())
- {
- Byte[] txt = new UTF8Encoding(true).GetBytes("New file.");
- fs.Write(txt, 0, txt.Length);
- Byte[] author = new UTF8Encoding(true).GetBytes("Author Mahesh Chand");
- fs.Write(author, 0, author.Length);
- }
- // Get File Name
- string justFileName = fi.Name;
- Console.WriteLine("File Name: {0}", justFileName);
- // Get file name with full path
- string fullFileName = fi.FullName;
- Console.WriteLine("File Name: {0}", fullFileName);
- // Get file extension
- string extn = fi.Extension;
- Console.WriteLine("File Extension: {0}", extn);
- // Get directory name
- string directoryName = fi.DirectoryName;
- Console.WriteLine("Directory Name: {0}", directoryName);
- // File Exists ?
- bool exists = fi.Exists;
- Console.WriteLine("File Exists: {0}", exists);
- if (fi.Exists)
- {
- // Get file size
- long size = fi.Length;
- Console.WriteLine("File Size in Bytes: {0}", size);
- // File ReadOnly ?
- bool IsReadOnly = fi.IsReadOnly;
- Console.WriteLine("Is ReadOnly: {0}", IsReadOnly);
- // Creation, last access, and last write time
- DateTime creationTime = fi.CreationTime;
- Console.WriteLine("Creation time: {0}", creationTime);
- DateTime accessTime = fi.LastAccessTime;
- Console.WriteLine("Last access time: {0}", accessTime);
- DateTime updatedTime = fi.LastWriteTime;
- Console.WriteLine("Last write time: {0}", updatedTime);
- }

Shadab KhanPosted Oct 27, 2014, 1:41 PM
plz provied for the xml using c# article
Shadab KhanPosted Oct 27, 2014, 1:39 PM
thanks for...................eassy and good way content