On several occasions in my short life I have ran across coders that insist on not using the prebuilt classes and functions that come with .net. I can understand not using a 3rd party lib when you write the entire product for the ground up, but if you are using .net you might as well use it to its fullest extent.
Take the following code:
9 using (FileStream fs = new FileStream(FilePath, FileMode.Open))
11 using (BinaryReader br = new BinaryReader(fs))
12 rawTiffData = br.ReadBytes((int)fs.Length);
14 tiffData = Convert.ToBase64String(rawTiffData);
16 string name = tiffPath.Substring(tiffPath.LastIndexOf('\\') + 1,
17 tiffPath.LastIndexOf('.') - tiffPath.LastIndexOf('\\') - 1);
It will open up a tiff file and read in all of the bytes and then convert it to base 64 encoding. Then he gets the name of the file without its extension. Let's do the same thing but using the .Net functions that should be used.
9 rawTiffData = File.ReadAllBytes(this.FilePath);
10 tiffData = Convert.ToBase64String(rawTiffData);
11 string name = Path.GetFileNameWithoutExtension(this.FilePath);
The second section of code is almost self documenting. You can at a glance see what is going where and why. You also don't have to worry about getting your substring wrong or someone a year down the road coming in and making a small change to the substring call to make it better. Adding a bug that is not trivial to find.