Get file version using c#

using System; using System.Diagnostics;     class MainClass { static void Main(string[] args) { FileVersionInfo info = FileVersionInfo.GetVersionInfo("c:\\a.txt");     Console.WriteLine("File Version: " + info.FileVersion); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Example of file system watcher

  using System; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.IO;     public class Test { public static void Main(){       FileSystemWatcher watcher = new FileSystemWatcher(); Console.WriteLine("Started….");   //watcher.SynchronizingObject = this;   watcher.Path =Path.GetDirectoryName(@"C:\Java_Dev\"); watcher.Filter = Path.GetFileName(@"c:\a.txt"); watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.Size;   watcher.Deleted += new System.IO.FileSystemEventHandler(OnDelete); watcher.Renamed += new […]
Continue reading…

Enjoyed this post? Share it!

 
 

Filestream with filemode.create and filemode.open

  using System; using System.IO; using System.Text;     class MainClass { static void Main() { using (FileStream fs = new FileStream("test.txt", FileMode.Create)) { using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) { w.WriteLine(124.23M); w.WriteLine("Test string"); w.WriteLine(’!’); } } Console.WriteLine("Press Enter to read the information."); Console.ReadLine(); // Open the file in read-only mode. using (FileStream fs […]
Continue reading…

Enjoyed this post? Share it!

 
 

Search for file using csharp

using System; using System.IO; public class FileSearch { public static void Main() { String searchName = "win"; DirectoryInfo myDir = new DirectoryInfo(@"c:\Program Files"); SearchDirectories(myDir, searchName); }     public static void SearchDirectories(DirectoryInfo dir, String target) { FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { if (file.Name.IndexOf(target) > -1) { Console.WriteLine(file.Name); } }   […]
Continue reading…

Enjoyed this post? Share it!

 
 

Read binary file using file pointer

using System; using System.IO; using System.Text;     class Class1{ static void Main(string[] args) { byte[] byData = new byte[100]; char[] charData = new Char[100];     try { FileStream aFile = new FileStream("practice.txt",FileMode.Open); aFile.Seek(55,SeekOrigin.Begin); aFile.Read(byData,0,100); } catch(IOException e) { Console.WriteLine("An IO exception has been thrown!"); Console.WriteLine(e.ToString()); Console.ReadLine(); return; }     Decoder d = […]
Continue reading…

Enjoyed this post? Share it!

 
 

Example of file move using MoveTo

  using System; using System.IO;     class Class1 { static void Main(string[] args) { string [] cla = Environment.GetCommandLineArgs(); if (cla.GetUpperBound(0) == 2) { FileInfo fi = new FileInfo(cla[1]); fi.MoveTo(cla[2]); Console.WriteLine("File Created : " + fi.CreationTime.ToString()); Console.WriteLine("Moved to : " + cla[2]); } else Console.WriteLine ("Usage: mv <source file> <destination file>"); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Inheritance of ideserializationcallback class

using System; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO;   [Serializable] public class BookRecord : IDeserializationCallback { public String title; public int asin; [NonSerialized] public int rank;     public BookRecord(String title, int asin) { this.title = title; this.asin = asin; rank = GetSalesRank(); }     public int GetSalesRank() { Random r = new Random(); […]
Continue reading…

Enjoyed this post? Share it!

 
 

Encoding.utf8/unicode/utf32 using getstring

using System; public class MainClass { public static void Main() { byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes("0123456789"); byte[] utf16Bytes = System.Text.Encoding.Unicode.GetBytes("0123456789"); byte[] utf32Bytes = System.Text.Encoding.UTF32.GetBytes("0123456789");     string original1 = System.Text.Encoding.UTF8.GetString(utf8Bytes); string original2 = System.Text.Encoding.Unicode.GetString(utf16Bytes); string original3 = System.Text.Encoding.UTF32.GetString(utf32Bytes);     Console.WriteLine(original1); Console.WriteLine(original2); Console.WriteLine(original3); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Encoding.utf8/unicode/utf32/ using getbytes

using System;     public class MainClass { public static void Main() { byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes("0123456789"); byte[] utf16Bytes = System.Text.Encoding.Unicode.GetBytes("0123456789"); byte[] utf32Bytes = System.Text.Encoding.UTF32.GetBytes("0123456789");     Console.WriteLine(utf8Bytes.Length); Console.WriteLine(utf16Bytes.Length); Console.WriteLine(utf32Bytes.Length); } }
Continue reading…

Enjoyed this post? Share it!

 
 

Encoding: unicode ascii getbytes getstring

using System; using System.IO; using System.Text;     class MainClass { public static void Main() { using (StreamWriter output = new StreamWriter("output.txt")) { string srcString = "Area = \u03A0r^2"; output.WriteLine("Source Text : " + srcString);     byte[] utf16String = Encoding.Unicode.GetBytes(srcString); output.WriteLine("UTF-16 Bytes: {0}",BitConverter.ToString(utf16String));     byte[] utf8String = Encoding.UTF8.GetBytes(srcString); byte[] asciiString = Encoding.ASCII.GetBytes(srcString);   […]
Continue reading…

Enjoyed this post? Share it!

 
 

String encoding example

  using System; using System.IO; using System.Text;     class Test { public static void Main() { using (StreamWriter output = new StreamWriter("practice.txt")) { // Create and write a string containing the symbol for Pi. string srcString = "Area = \u03A0r^2";     // Convert the UTF-16 encoded source string to UTF-8 and ASCII. byte[] […]
Continue reading…

Enjoyed this post? Share it!

 
 

Get drive type using c#

    using System; using System.IO;     class MainClass { static void Main(string[] args) { FileInfo file = new FileInfo("c:\\a.txt");     // Display drive information. DriveInfo drv = new DriveInfo(file.FullName);     Console.Write("Drive: "); Console.WriteLine(drv.Name);     if (drv.IsReady) { Console.Write("Drive type: "); Console.WriteLine(drv.DriveType.ToString()); } } }
Continue reading…

Enjoyed this post? Share it!