<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5787986616878478054</id><updated>2012-02-16T12:08:06.666-08:00</updated><title type='text'>Files  and  Directories</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-5621019123207824378</id><published>2009-05-30T07:04:00.000-07:00</published><updated>2009-05-30T07:05:38.460-07:00</updated><title type='text'>Size of Folder in Bytes (Deep or Shallow)</title><content type='html'>using System;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;public class Folder {&lt;br /&gt;    private static double sizeInBytes;&lt;br /&gt;&lt;br /&gt;    public static double Size(string directory, bool deep) {&lt;br /&gt;        DirectoryInfo dir = new DirectoryInfo(directory);&lt;br /&gt;        foreach(FileInfo f in dir.GetFiles()) {&lt;br /&gt;            sizeInBytes += f.Length;&lt;br /&gt;        }&lt;br /&gt;        if(deep) {&lt;br /&gt;            foreach(DirectoryInfo d in dir.GetDirectories()) {&lt;br /&gt;                Size(d.FullName, deep);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        return sizeInBytes;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    static void Main() {&lt;br /&gt;        Console.WriteLine("The total folder size in bytes is {0}",  Folder.Size(@"c:\sonysys", true));&lt;br /&gt;    }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-5621019123207824378?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/5621019123207824378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/size-of-folder-in-bytes-deep-or-shallow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5621019123207824378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5621019123207824378'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/size-of-folder-in-bytes-deep-or-shallow.html' title='Size of Folder in Bytes (Deep or Shallow)'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-865267656825840234</id><published>2009-05-30T07:03:00.001-07:00</published><updated>2009-05-30T07:03:51.623-07:00</updated><title type='text'>Ini File class</title><content type='html'>using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;//This namespace is for easy INI reading ad writing, designed to be practically errorless, you dont need to worry about things like if .exists .add .set etc, just .set&lt;br /&gt;//XML is similar to INI, but not as simple and easily modified by humans&lt;br /&gt;//INI is ideal for server settings etc.&lt;br /&gt;&lt;br /&gt;//any keys found NOT under a group header will be put in group MAIN&lt;br /&gt;&lt;br /&gt;//WARNING: THIS INI FILE DOES NOT SUPPORT COMMENTS&lt;br /&gt;//FORMAT IS AS FOLLOWS:&lt;br /&gt;//[GROUP]&lt;br /&gt;//item1=True&lt;br /&gt;//item2=some text here&lt;br /&gt;//[GROUP2]&lt;br /&gt;//soemthing=3&lt;br /&gt;using System.IO;&lt;br /&gt;namespace EasyINI&lt;br /&gt;{&lt;br /&gt;    //A class to handle all file IO for multiple savable settings&lt;br /&gt;    //This class will create on-demand, an INI file of settings, keys need not be added before being assigned&lt;br /&gt;    public class INIFile&lt;br /&gt;    {&lt;br /&gt;        //this class handles the saving and loading of the file&lt;br /&gt;        protected string fname;&lt;br /&gt;        protected List&lt;string&gt; inigroupnames;&lt;br /&gt;        protected List&lt;inigroup&gt; inigroups;&lt;br /&gt;&lt;br /&gt;        public INIFile(string @filename)&lt;br /&gt;        {&lt;br /&gt;            fname = filename;&lt;br /&gt;            inigroups = new List&lt;inigroup&gt;();&lt;br /&gt;            inigroupnames = new List&lt;string&gt;();&lt;br /&gt;            reloadFile();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public INIGroup Group(string name)&lt;br /&gt;        {&lt;br /&gt;            name = name.ToUpper();&lt;br /&gt;            int i = inigroupnames.IndexOf(name);&lt;br /&gt;            if (i == -1)&lt;br /&gt;            {&lt;br /&gt;                return null;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                return inigroups[i];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void setValue(string group, string key, string value)&lt;br /&gt;        {&lt;br /&gt;            addGroup(group); //create the group (if not already existing)&lt;br /&gt;            Group(group).setValue(key, value); //set the value&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public string getValue(string group, string key)&lt;br /&gt;        {&lt;br /&gt;            group = group.ToUpper();&lt;br /&gt;            key = key.ToLower();&lt;br /&gt;            if (inigroupnames.IndexOf(group) == -1)&lt;br /&gt;            {&lt;br /&gt;                return string.Empty;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                return Group(group).getValue(key);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void addGroup(string group)&lt;br /&gt;        {&lt;br /&gt;            group = group.ToUpper();&lt;br /&gt;            if (inigroupnames.IndexOf(group) == -1)&lt;br /&gt;            {&lt;br /&gt;                inigroupnames.Add(group);&lt;br /&gt;                inigroups.Add(new INIGroup(this));&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public bool saveFile() //bool returned indicates the success of the save process&lt;br /&gt;        {&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                FileStream strm = new FileStream(fname, FileMode.Create, FileAccess.Write);&lt;br /&gt;                StreamWriter W = new StreamWriter(strm);&lt;br /&gt;                if(inigroupnames.Count &gt; 0)&lt;br /&gt;                {&lt;br /&gt;                    for (int i = 0; i &lt; inigroupnames.Count; i++)&lt;br /&gt;                    {&lt;br /&gt;                        INIGroup grp = inigroups[i];&lt;br /&gt;                        if (grp.getCount() &gt; 0) //only save this group if it has content&lt;br /&gt;                        {&lt;br /&gt;                            W.WriteLine("[" + inigroupnames[i] + "]");&lt;br /&gt;                            for (int k = 0; k &lt; grp.getCount(); k++)&lt;br /&gt;                                W.WriteLine(grp.getKey(k) + @"=" + grp.getValue(k));&lt;br /&gt;                            W.WriteLine(" ");&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;                W.Close();&lt;br /&gt;                strm.Close();&lt;br /&gt;                return true;&lt;br /&gt;            }&lt;br /&gt;            catch&lt;br /&gt;            {&lt;br /&gt;                return false;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void reloadFile()&lt;br /&gt;        {&lt;br /&gt;            inigroups.Clear();&lt;br /&gt;            inigroupnames.Clear();&lt;br /&gt;&lt;br /&gt;            if (File.Exists(fname))&lt;br /&gt;            {&lt;br /&gt;                string strline;&lt;br /&gt;                string currentGroup = "MAIN";&lt;br /&gt;                FileStream strm = new FileStream(fname, FileMode.Open, FileAccess.Read);&lt;br /&gt;                StreamReader R = new StreamReader(strm);&lt;br /&gt;                while (R.EndOfStream != true)&lt;br /&gt;                {&lt;br /&gt;                    strline = R.ReadLine(); //get line&lt;br /&gt;                    if (strline.StartsWith("["))&lt;br /&gt;                    {&lt;br /&gt;                        //this is a group header&lt;br /&gt;                        currentGroup = strline.Substring(1, strline.Length - 2);&lt;br /&gt;                    }&lt;br /&gt;                    else&lt;br /&gt;                    {&lt;br /&gt;                        //this is a key=value entry&lt;br /&gt;                        string[] keyval = strline.Split('=');&lt;br /&gt;                        if (keyval.Length == 2)&lt;br /&gt;                            setValue(currentGroup, keyval[0], keyval[1]);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;                R.Close();&lt;br /&gt;                strm.Close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //This sub-class is used by the INIFile class, it handles the keys and values within an INI group&lt;br /&gt;    public class INIGroup&lt;br /&gt;    {&lt;br /&gt;        //this class handles the settings of values&lt;br /&gt;        protected INIFile owner;&lt;br /&gt;        public List&lt;string&gt; inikeys;&lt;br /&gt;        public List&lt;string&gt; inivalues;&lt;br /&gt;        public INIGroup(INIFile parent)&lt;br /&gt;        {&lt;br /&gt;            owner = parent;&lt;br /&gt;            inikeys = new List&lt;string&gt;();&lt;br /&gt;            inivalues = new List&lt;string&gt;();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void setValue(string key, string value)&lt;br /&gt;        {&lt;br /&gt;            key = key.ToLower();&lt;br /&gt;            int i = inikeys.IndexOf(key);&lt;br /&gt;            if (i == -1)&lt;br /&gt;            {&lt;br /&gt;                inikeys.Add(key);&lt;br /&gt;                inivalues.Add(value);&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                inivalues[i] = value;&lt;br /&gt;            }&lt;br /&gt;            owner.saveFile();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public string getValue(string key)&lt;br /&gt;        {&lt;br /&gt;            key = key.ToLower();&lt;br /&gt;            int i = inikeys.IndexOf(key);&lt;br /&gt;            if (i == -1)&lt;br /&gt;            {&lt;br /&gt;                return string.Empty;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                return inivalues[i];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public string getKey(int index)&lt;br /&gt;        {&lt;br /&gt;            if (index &gt; -1 &amp;amp;&amp;amp; index &lt; getCount())&lt;br /&gt;            {&lt;br /&gt;                return inikeys[index];&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                //out of range&lt;br /&gt;                throw new IndexOutOfRangeException("Index was out of range, must be non-negative and less than total key count");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public string getValue(int index)&lt;br /&gt;        {&lt;br /&gt;            if (index &gt; -1 &amp;amp;&amp;amp; index &lt; getCount())&lt;br /&gt;            {&lt;br /&gt;                return inivalues[index];&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                //out of range&lt;br /&gt;                throw new IndexOutOfRangeException("Index was out of range, must be non-negative and less than total key count");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public int getCount()&lt;br /&gt;        {&lt;br /&gt;            return inikeys.Count;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-865267656825840234?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/865267656825840234/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/ini-file-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/865267656825840234'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/865267656825840234'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/ini-file-class.html' title='Ini File class'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-674258679380176864</id><published>2009-05-30T07:02:00.001-07:00</published><updated>2009-05-30T07:02:39.518-07:00</updated><title type='text'>Browse For Folder in .NET 1.0</title><content type='html'>//Have To Reference System.Design.dll&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt; Usage:&lt;br /&gt; -&lt;br /&gt; BrowseForFolder browse = new BrowseForFolder();&lt;br /&gt; string savePath = browse.Show();&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Windows.Forms;&lt;br /&gt;using System.Windows.Forms.Design;&lt;br /&gt;namespace iCode_Library.NET&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;        public class BrowseForFolder: FolderNameEditor&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;                FolderNameEditor.FolderBrowser dirBrowser;&lt;br /&gt;                public BrowseForFolder()&lt;br /&gt;                {&lt;br /&gt;                        dirBrowser = new FolderNameEditor.FolderBrowser();&lt;br /&gt;                }&lt;br /&gt;                public string Show()&lt;br /&gt;                {&lt;br /&gt;                        //set the Description label&lt;br /&gt;                        dirBrowser.Description = "Select Folder";&lt;br /&gt;                        dirBrowser.ShowDialog(); //show the Windows&lt;br /&gt;                        return dirBrowser.DirectoryPath + @"\"; // return whatever path choosen&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-674258679380176864?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/674258679380176864/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/browse-for-folder-in-net-10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/674258679380176864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/674258679380176864'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/browse-for-folder-in-net-10.html' title='Browse For Folder in .NET 1.0'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-5978534559575637466</id><published>2009-05-30T07:01:00.002-07:00</published><updated>2009-05-30T07:02:08.223-07:00</updated><title type='text'>File Content To Array</title><content type='html'>private ArrayList fileContentToArrayList(string filePath)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    System.Collections.ArrayList arrListLines = new System.Collections.ArrayList();&lt;br /&gt;    //read the file content one by one&lt;br /&gt;    try&lt;br /&gt;    {&lt;br /&gt;        StreamReader fl = new StreamReader(filePath, System.Text.Encoding.ASCII);&lt;br /&gt;        //StreamReader fl = File.OpenText(filePath,);&lt;br /&gt;        string line = "";&lt;br /&gt;        while((line = fl.ReadLine()) != null )&lt;br /&gt;        {&lt;br /&gt;            arrListLines.Add(line);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;    catch(Exception e)&lt;br /&gt;    {&lt;br /&gt;        System.Windows.Forms.MessageBox.Show(e.Message, "Failed reading file");&lt;br /&gt;        return null;&lt;br /&gt;    }&lt;br /&gt;    return arrListLines;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-5978534559575637466?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/5978534559575637466/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/file-content-to-array.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5978534559575637466'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5978534559575637466'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/file-content-to-array.html' title='File Content To Array'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-5266220244929570867</id><published>2009-05-30T07:01:00.001-07:00</published><updated>2009-05-30T07:01:22.334-07:00</updated><title type='text'>Reading a text file with StreamReader</title><content type='html'>// Reading a text file with StreamReader&lt;br /&gt;&lt;br /&gt;  private void ImportCountries()&lt;br /&gt;  {&lt;br /&gt;    string delimiter = ",";&lt;br /&gt;    string fileName = @"c:\countrylist3.csv";&lt;br /&gt;&lt;br /&gt;    StreamReader sr = new StreamReader(fileName);&lt;br /&gt;&lt;br /&gt;    try&lt;br /&gt;    {&lt;br /&gt;      while (sr.Peek() &gt;= 0)&lt;br /&gt;      {&lt;br /&gt;        string r = sr.ReadLine();&lt;br /&gt;        string[] items = r.Split(delimiter.ToCharArray());&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;    finally&lt;br /&gt;    {&lt;br /&gt;      sr.Close();&lt;br /&gt;    }&lt;br /&gt;  }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-5266220244929570867?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/5266220244929570867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/reading-text-file-with-streamreader.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5266220244929570867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5266220244929570867'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/reading-text-file-with-streamreader.html' title='Reading a text file with StreamReader'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-7484673042966439301</id><published>2009-05-30T07:00:00.001-07:00</published><updated>2009-05-30T07:00:54.488-07:00</updated><title type='text'>Write file to response stream</title><content type='html'>// Wrtites temporary file to response stream and then delete&lt;br /&gt;&lt;br /&gt;Response.Clear();&lt;br /&gt;Response.ContentType = "image/tiff";&lt;br /&gt;Response.AddHeader("Content-Disposition", "attachment; filename=imageFile.tiff");&lt;br /&gt;Response.WriteFile(tempPath);&lt;br /&gt;Response.Flush();&lt;br /&gt;Response.Close();&lt;br /&gt;&lt;br /&gt;if(File.Exists(tempPath))&lt;br /&gt;{&lt;br /&gt;    File.Delete(tempPath);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-7484673042966439301?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/7484673042966439301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/write-file-to-response-stream.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/7484673042966439301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/7484673042966439301'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/write-file-to-response-stream.html' title='Write file to response stream'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-5236383524747580167</id><published>2009-05-30T06:59:00.003-07:00</published><updated>2009-05-30T06:59:55.995-07:00</updated><title type='text'>Short/Long path conversion</title><content type='html'>// Short/Long path conversion&lt;br /&gt;&lt;br /&gt;// Long To Short Path/File Name:&lt;br /&gt;&lt;br /&gt;[DllImport("kernel32.dll", CharSet = CharSet.Auto)]&lt;br /&gt;public static extern int GetShortPathName(&lt;br /&gt;[MarshalAs(UnmanagedType.LPTStr)] string path,&lt;br /&gt;[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,&lt;br /&gt;int shortPathLength&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;// ...&lt;br /&gt;&lt;br /&gt;StringBuilder shortPath = new StringBuilder(1024);&lt;br /&gt;GetShortPathName(textBoxFilename.Text, shortPath, shortPath.Capacity);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// Short To Long Path/File Names:&lt;br /&gt;&lt;br /&gt;[DllImport("kernel32.dll", CharSet = CharSet.Auto)]&lt;br /&gt;public static extern int GetLongPathName(&lt;br /&gt;[MarshalAs(UnmanagedType.LPTStr)]&lt;br /&gt;string path,&lt;br /&gt;[MarshalAs(UnmanagedType.LPTStr)]&lt;br /&gt;StringBuilder longPath,&lt;br /&gt;int longPathLength&lt;br /&gt;);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-5236383524747580167?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/5236383524747580167/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/shortlong-path-conversion.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5236383524747580167'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5236383524747580167'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/shortlong-path-conversion.html' title='Short/Long path conversion'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-9173397500683751739</id><published>2009-05-30T06:59:00.001-07:00</published><updated>2009-05-30T06:59:19.132-07:00</updated><title type='text'>Get file extension</title><content type='html'>// Get file extension&lt;br /&gt;&lt;br /&gt;FileInfo temp = new FileInfo(fileName);&lt;br /&gt; if (temp.Extension.ToUpper() == ".DOC")&lt;br /&gt; {&lt;br /&gt;     // ...&lt;br /&gt; }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-9173397500683751739?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/9173397500683751739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/get-file-extension.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/9173397500683751739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/9173397500683751739'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/get-file-extension.html' title='Get file extension'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-5084280359373205525</id><published>2009-05-30T06:58:00.001-07:00</published><updated>2009-05-30T06:58:46.671-07:00</updated><title type='text'>Wipe file</title><content type='html'>// Wipe file&lt;br /&gt;&lt;br /&gt;        public static void Wipe(string fileName)&lt;br /&gt;        {&lt;br /&gt;            if (File.Exists(fileName))&lt;br /&gt;            {&lt;br /&gt;                File.SetAttributes(fileName, FileAttributes.Normal);&lt;br /&gt;                Random rnd = new Random((int)DateTime.Now.Ticks);&lt;br /&gt;                FileStream file = File.Open(fileName, FileMode.Open, FileAccess.Write);&lt;br /&gt;                int fileLength = (int)file.Length;&lt;br /&gt;                int offset = 0;&lt;br /&gt;&lt;br /&gt;                const int BUFFER_SIZE = 100;&lt;br /&gt;                byte[][] buffers = new byte[4][];&lt;br /&gt;                buffers[0] = new byte[BUFFER_SIZE];&lt;br /&gt;                buffers[1] = new byte[BUFFER_SIZE];&lt;br /&gt;                buffers[2] = new byte[BUFFER_SIZE];&lt;br /&gt;                buffers[3] = new byte[BUFFER_SIZE];&lt;br /&gt;&lt;br /&gt;                rnd.NextBytes(buffers[0]);&lt;br /&gt;                rnd.NextBytes(buffers[2]);&lt;br /&gt;                for (int i = 0; i &lt; BUFFER_SIZE; i++)&lt;br /&gt;                {&lt;br /&gt;                    buffers[1][i] = 0;&lt;br /&gt;                    buffers[3][i] = 0xff;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                while (offset &lt; (fileLength - BUFFER_SIZE))&lt;br /&gt;                {&lt;br /&gt;                    for (int i = 0; i &lt; buffers.Length; i++)&lt;br /&gt;                    {&lt;br /&gt;                        file.Seek(offset, SeekOrigin.Begin);&lt;br /&gt;                        file.Write(buffers[0], 0, BUFFER_SIZE);&lt;br /&gt;                        file.Flush();&lt;br /&gt;                    }&lt;br /&gt;                    offset += 100;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                for (int i = 0; i &lt; buffers.Length; i++)&lt;br /&gt;                {&lt;br /&gt;                    file.Seek(offset, SeekOrigin.Begin);&lt;br /&gt;                    file.Write(buffers[0], 0, fileLength - offset);&lt;br /&gt;                    file.Flush();&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                file.Close();&lt;br /&gt;&lt;br /&gt;                file = File.Open(fileName, FileMode.Truncate, FileAccess.Write);&lt;br /&gt;                file.Flush();&lt;br /&gt;                file.Close();&lt;br /&gt;&lt;br /&gt;                File.Delete(fileName);&lt;br /&gt;            }&lt;br /&gt;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-5084280359373205525?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/5084280359373205525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/wipe-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5084280359373205525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/5084280359373205525'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/wipe-file.html' title='Wipe file'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-2214075721597352513</id><published>2009-05-30T06:57:00.000-07:00</published><updated>2009-05-30T06:58:13.571-07:00</updated><title type='text'>File lock</title><content type='html'>// Lock files so that no one else can access it:&lt;br /&gt;&lt;br /&gt; // --------&lt;br /&gt; // Method 1&lt;br /&gt; // --------&lt;br /&gt; string filename = "c:\\sample.htm";&lt;br /&gt; FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read,&lt;br /&gt; FileShare.None); //locks file&lt;br /&gt;&lt;br /&gt; // ...&lt;br /&gt;&lt;br /&gt; stream.Close(); //unlocks file&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; // --------&lt;br /&gt; // Method 1&lt;br /&gt; // --------&lt;br /&gt;&lt;br /&gt; string filename = "c:\\sample.htm";&lt;br /&gt; FileStream stream = File.Open(filename, FileMode.Open);&lt;br /&gt; stream.Lock(0, stream.Length); //locks file&lt;br /&gt;&lt;br /&gt; // ...&lt;br /&gt;&lt;br /&gt; stream.Unlock(0, stream.Length); //unlocks file&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-2214075721597352513?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/2214075721597352513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/file-lock.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2214075721597352513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2214075721597352513'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/file-lock.html' title='File lock'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-988475525922855071</id><published>2009-05-30T06:56:00.000-07:00</published><updated>2009-05-30T06:57:40.419-07:00</updated><title type='text'>List Files in a Directory in C#</title><content type='html'>// List Files in a Directory in C#&lt;br /&gt;&lt;br /&gt;// You can get an array of files (their path) by using:&lt;br /&gt;fileArray = Directory.GetFiles(yourPath);&lt;br /&gt;&lt;br /&gt;// You can display all of the images in a directory by using:&lt;br /&gt;ArrayList pics = new ArrayList();&lt;br /&gt;&lt;br /&gt;string myFile;&lt;br /&gt;string code;&lt;br /&gt;const string YOUR_DIRECTORY = "/images/";&lt;br /&gt;&lt;br /&gt;foreach (myFile in Directory.GetFiles(Server.MapPath(YOUR_DIRECTORY), "*.gif"))&lt;br /&gt;{&lt;br /&gt;    image = YOUR_DIRECTORY + Path.GetFileName(myFile);&lt;br /&gt;    code = &lt;"img src=\"" + image + "\"&gt;";&lt;br /&gt;&lt;br /&gt;    // add the image to your ArrayList&lt;br /&gt;    pics.Add(code);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Bind the pics to a DataList&lt;br /&gt;dlImages.DataSource = pics;&lt;br /&gt;dlImages.DataBind;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-988475525922855071?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/988475525922855071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/list-files-in-directory-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/988475525922855071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/988475525922855071'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/list-files-in-directory-in-c.html' title='List Files in a Directory in C#'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-2849206777988642827</id><published>2009-05-30T06:51:00.000-07:00</published><updated>2009-05-30T06:52:19.591-07:00</updated><title type='text'>Set a file as read-only</title><content type='html'>public void SetReadOnly(string fullName, bool readOnly)&lt;br /&gt;{&lt;br /&gt;        FileInfo filePath = new FileInfo(fullName);&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;                if (filePath.Exists)&lt;br /&gt;                {&lt;br /&gt;                        FileAttributes attr;&lt;br /&gt;                        if (readOnly)&lt;br /&gt;                        {&lt;br /&gt;                                attr = (FileAttributes)&lt;br /&gt;                                (filePath.Attributes | FileAttributes.ReadOnly);&lt;br /&gt;                        }&lt;br /&gt;                        else&lt;br /&gt;                        {&lt;br /&gt;                                attr = (FileAttributes)&lt;br /&gt;                                (filePath.Attributes - FileAttributes.ReadOnly);&lt;br /&gt;                        }&lt;br /&gt;                        File.SetAttributes(filePath.FullName, attr);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;        catch (IOException e)&lt;br /&gt;        {&lt;br /&gt;                System.Diagnostics.Debug.WriteLine(e.Source);&lt;br /&gt;                System.Diagnostics.Debug.WriteLine(e.Message);&lt;br /&gt;                System.Diagnostics.Debug.WriteLine(e.StackTrace);&lt;br /&gt;        }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-2849206777988642827?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/2849206777988642827/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/set-file-as-read-only_30.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2849206777988642827'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2849206777988642827'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/set-file-as-read-only_30.html' title='Set a file as read-only'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-2452645894130811857</id><published>2009-05-30T06:50:00.000-07:00</published><updated>2009-05-30T06:51:36.864-07:00</updated><title type='text'>Write a binary file</title><content type='html'>public bool WriteBinaryFile(string filePath, byte[] contents)&lt;br /&gt;{&lt;br /&gt;        bool okok = true;&lt;br /&gt;&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;                using (FileStream fs = new FileStream(filePath, FileMode.CreateNew))&lt;br /&gt;                {&lt;br /&gt;                    using (BinaryWriter w = new BinaryWriter(fs))&lt;br /&gt;&lt;br /&gt;                    {&lt;br /&gt;                        w.Write(contents);&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;        catch (IOException e)&lt;br /&gt;        {&lt;br /&gt;                okok = false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return okok;&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-2452645894130811857?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/2452645894130811857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/write-binary-file_30.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2452645894130811857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/2452645894130811857'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/write-binary-file_30.html' title='Write a binary file'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-1314287618577788030</id><published>2009-05-30T06:45:00.000-07:00</published><updated>2009-05-30T06:46:08.564-07:00</updated><title type='text'>Recursively Search Directory for a File</title><content type='html'>System.Collections.ArrayList files = new System.Collections.ArrayList();&lt;br /&gt; DirSearch(@"C:",ref files);&lt;br /&gt;//Method to Search Directory for specified file Type.Paste it outside the function&lt;br /&gt;public void DirSearch(string sDir,ref System.Collections.ArrayList files)&lt;br /&gt;{&lt;br /&gt;         try&lt;br /&gt;        {&lt;br /&gt;           foreach (string d in System.IO.Directory.GetDirectories(sDir))&lt;br /&gt;           {&lt;br /&gt;                foreach (string f in System.IO.Directory.GetFiles(d, "*.txt"))&lt;br /&gt;                {&lt;br /&gt;                   files.Add(f);&lt;br /&gt;                }&lt;br /&gt;                DirSearch(d,ref files);&lt;br /&gt;           }&lt;br /&gt;        }&lt;br /&gt;        catch (System.Exception excpt)&lt;br /&gt;        {&lt;br /&gt;                Console.WriteLine(excpt.Message);&lt;br /&gt;        }&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-1314287618577788030?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/1314287618577788030/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/recursively-search-directory-for-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/1314287618577788030'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/1314287618577788030'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/recursively-search-directory-for-file.html' title='Recursively Search Directory for a File'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5787986616878478054.post-4034484091040055755</id><published>2009-05-30T06:44:00.000-07:00</published><updated>2009-05-30T06:45:16.838-07:00</updated><title type='text'>How to Read a Text File (with a single call to sReader.ReadToEnd())</title><content type='html'>public static string getFileAsString(string fileName) {&lt;br /&gt;         StreamReader sReader = null;&lt;br /&gt;         string contents = null;&lt;br /&gt;         try {&lt;br /&gt;            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);&lt;br /&gt;            sReader = new StreamReader(fileStream);&lt;br /&gt;            contents = sReader.ReadToEnd();&lt;br /&gt;         } finally {&lt;br /&gt;           if(sReader != null) {&lt;br /&gt;               sReader.Close();&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         return contents;&lt;br /&gt;      }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5787986616878478054-4034484091040055755?l=filesanddirectoriesincsharp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://filesanddirectoriesincsharp.blogspot.com/feeds/4034484091040055755/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/how-to-read-text-file-with-single-call.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/4034484091040055755'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5787986616878478054/posts/default/4034484091040055755'/><link rel='alternate' type='text/html' href='http://filesanddirectoriesincsharp.blogspot.com/2009/05/how-to-read-text-file-with-single-call.html' title='How to Read a Text File (with a single call to sReader.ReadToEnd())'/><author><name>Avinash Tiwari</name><uri>http://www.blogger.com/profile/15802356010881135678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://1.bp.blogspot.com/_LGmdihF6s00/SbOiiR5usKI/AAAAAAAAACo/AetFd4M1LfU/S220/UploadedImage.jpg'/></author><thr:total>0</thr:total></entry></feed>
