Compares the content of 2 files

image_pdfimage_print
   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
    class MainClass{
        /// ---------------------------------------------------------------
        /// <summary>
        /// This method compares the content of 2 files. A return value of true
        /// indicates that the contents of the files
        /// are the same. A return value of false indicates that the 
        /// files are not the same.
    /// </summary>
    /// <param name="firstFile">first file to be compared against the second</param>
    /// <param name="secondFile">second file to be compared against the first</param>
    /// <returns>true if they are the same, false otherwise</returns>
        /// <remarks>
        /// This method has been modified to increase the speed in which this
        /// file comparing operation performs.
        /// 
        /// The MSDN knowledge base:
        /// How to create a File-Compare function in Visual C#
        /// http://support.microsoft.com/default.aspx?scid=kb;en-us;320348
        /// was used to assist in speeding up this operation.
        /// </remarks>
        /// ---------------------------------------------------------------
    public static bool Compare(FileInfo firstFile, FileInfo secondFile)
    {
      if (!firstFile.Exists) 
      {
        string message = "File &#039;" + firstFile.FullName + "&#039; does not exist";
        throw new FileNotFoundException(message);
      }

      if (!secondFile.Exists) 
      {
        string message = "File &#039;" + secondFile.FullName + "&#039; does not exist";
        throw new FileNotFoundException(message);
      }


      // Check Each byte
      FileStream fs1 = new FileStream(firstFile.FullName, FileMode.Open, FileAccess.Read);
            FileStream fs2 = new FileStream(secondFile.FullName, FileMode.Open, FileAccess.Read);
                     
            // Check the file sizes. If they are not the same, the files 
            // are not the same.
            if (fs1.Length != fs2.Length)
            {
                // Close the file
                fs1.Close();
                fs2.Close();

                // Return false to indicate files are different
                return false;
            }

            int file1byte;
            int file2byte;

            // Read and compare a byte from each file until either a
            // non-matching set of bytes is found or until the end of
            // file1 is reached.
            do
            {
                // Read one byte from each file.
                file1byte = fs1.ReadByte();
                file2byte = fs2.ReadByte();
            }
            while ((file1byte == file2byte) &amp;&amp; (file1byte != -1));

            // Close the files.
            fs1.Close();
            fs2.Close();

            // Return the success of the comparison. "file1byte" is 
            // equal to "file2byte" at this point only if the files are 
            // the same.
            return ((file1byte - file2byte) == 0);

    }

        


        /// <summary>
        /// Compare the contents two files.
        /// </summary>
        /// <param name="firstFile">first file to be compared against the second</param>
        /// <param name="secondFile">second file to be compared against the first</param>
        /// <returns>true if they are the same, false otherwise</returns>
        public static bool Compare(string firstFile, string secondFile)
        {
            FileInfo fiFirstFile = new FileInfo(firstFile);
            FileInfo fiSecondFile = new FileInfo(secondFile);

            return Compare(fiFirstFile, fiSecondFile);
        }
   }
}

   
     


Returns a human-readable version of the file size (original is in bytes).

image_pdfimage_print
   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
    class MainClass{
  
    /// <summary>The number of bytes in a kilobyte.</summary>
    public const long ONE_KB = 1024;

    /// <summary>The number of bytes in a megabyte.</summary>
    public const long ONE_MB = ONE_KB * ONE_KB;


    /// <summary> The number of bytes in a gigabyte.</summary>
    public const long ONE_GB = ONE_KB * ONE_MB;




    /// --------------------------------------------------------------------------
    /// <summary>
    /// Returns a human-readable version of the file size (original is in bytes).
    /// </summary>
    /// <param name="size">The number of bytes.</param>
    /// <returns>A human-readable display value (includes units).</returns>
    /// --------------------------------------------------------------------------
    public static string DisplaySize(long size) 
    {
      string displaySize;

      if (size / ONE_GB > 0) 
      {
        displaySize = Convert.ToString(size / ONE_GB) + " GB";
      } 
      else if (size / ONE_MB > 0) 
      {
        displaySize = Convert.ToString(size / ONE_MB) + " MB";
      } 
      else if (size / ONE_KB > 0) 
      {
        displaySize = Convert.ToString(size / ONE_KB) + " KB";
      } 
      else 
      {
        displaySize = Convert.ToString(size) + " bytes";
      }

      return displaySize;
    }

   }
}

   
     


Uses StreamReader and StreamWriter object using different encoding to translate a file from one to another

image_pdfimage_print
   

/*
C# Programming Tips &amp; Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

// StrmCnvt.cs -- Uses StreamReader and StreamWriter object using different
//                encoding to translate a file from one to another
//
//                Compile this program with the following command line:
//                    C:>csc StrmCnvt.cs
using System;
using System.IO;
using System.Text;

namespace nsStreams
{
    public class StrmCnvt
    {
        static public void Main ()
        {
            FileStream istrm;
            FileStream ostrm;
            StreamReader reader;
            StreamWriter writer;
            try
            {
// Open the input file
                istrm = new FileStream ("./StrmRdr.txt", FileMode.Open, FileAccess.Read);
// Link a stream reader to the stream
                reader = new StreamReader (istrm, Encoding.ASCII);
            }
            catch (Exception e)
            {
                Console.WriteLine (e.Message);
                Console.WriteLine ("Cannot open ./StrmRdr.txt");
                return;
            }
            try
            {
// Open the output file
                ostrm = new FileStream ("./StrmRdr.Uni", FileMode.OpenOrCreate, FileAccess.Write);
// Link a stream reader to the stream
                writer = new StreamWriter (ostrm, Encoding.Unicode);
            }
            catch (Exception e)
            {
                Console.WriteLine (e.Message);
                Console.WriteLine ("Cannot open ./StrmRdr.Uni");
                return;
            }
            ostrm.SetLength (0);
            while (reader.Peek () >= 0)
            {
                string str = reader.ReadLine ();
                writer.WriteLine (str);
            }
            reader.Close ();
            istrm.Close ();
            writer.Close ();
            ostrm.Close ();
        }
    }
}
//File: StrmRdr.txt

/*
                 I Hear America Singing

I hear American Mouth-Songs, the varied carols I hear;
Those of mechanics -- each one singing his, as it should be,
        blithe and strong;
The carpenter singing his, as he measures his plank or beam,
The mason singing his, as he makes ready for work, or leaves
        off work;
The boatman singing what belongs to him in his boat -- the
        deckhand singing on the steamboat deck;
The shoemaker singing as he sits on his bench -- the hatter
        singing as he stands;
The wood-cutter&#039;s song -- the ploughboy&#039;s, on his way in the
        morning, or at the noon intermission, or at sundown;
The delicious singing of the mother -- or of the young wife at
        work -- or of the girl sewing or washing -- Each singing
        what belongs to her, and to none else;
The day what belongs to the day -- At night, the party of young
        fellows, robust, friendly;
Singing, with open mouths, their strong melodious songs.

                             -- Walt Whitman, 1860

*/

           
          


Read/Write File Transacted

image_pdfimage_print
   
 
/*==
== Copyright : BlueCurve (c)
== Licence   : Gnu/GPL v2.x
== Author    : Teddy Albina
== Email     : bluecurveteam@gmail.com
== Web site  : http://www.codeplex.com/BlueCurve
*/
using System;
using System.IO;
using System.Text;
using System.Transactions;
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;

namespace BlueCurve.Search.Common.IO
{
    /// <summary>
    /// Fournit des m&eacute;thodes de gestions du syst&egrave;me de fichier
    /// </summary>
    public class CommonStream
    {
        #region Import native methods

        /// <summary>
        /// M&eacute;thode native v&eacute;rifiant si un r&eacute;pertoire est vide
        /// </summary>
        /// <param name="pszPath">Chemin du r&eacute;pertoire &agrave; tester</param>
        /// <returns>bool</returns>
        [DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
        private extern static bool PathIsDirectoryEmpty(string pszPath);

        #region &#039;Kernel transaction manager api management&#039;

        /// <summary>
        /// Represente un handle de transaction
        /// </summary>
        public sealed class SafeTransactionHandle : SafeHandleZeroOrMinusOneIsInvalid
        {
            private SafeTransactionHandle()
                : base(true)
            {
            }

            public SafeTransactionHandle(IntPtr preexistingHandle, bool ownsHandle)
                : base(ownsHandle)
            {
                SetHandle(preexistingHandle);
            }

            public enum FileAccess
            {
                GENERIC_READ = unchecked((int)0x80000000),
                GENERIC_WRITE = 0x40000000
            }

            [Flags]
            public enum FileShare
            {
                FILE_SHARE_NONE = 0x00,
                FILE_SHARE_READ = 0x01,
                FILE_SHARE_WRITE = 0x02,
                FILE_SHARE_DELETE = 0x04
            }

            public enum FileMode
            {
                CREATE_NEW = 1,
                CREATE_ALWAYS = 2,
                OPEN_EXISTING = 3,
                OPEN_ALWAYS = 4,
                TRUNCATE_EXISTING = 5
            }

            [DllImport("Kernel32.dll", SetLastError = true)]
            private static extern bool CloseHandle(IntPtr handle);

            override protected bool ReleaseHandle()
            {
                return CloseHandle(handle);
            }
        }

        /// <summary>
        /// Importation de la fonction native CreateFileTransacted() permettant
        /// de cr&eacute;er une transaction ntfs
        /// </summary>
        /// <returns>SafeFileHandle</returns>
        [DllImport("Kernel32.Dll", EntryPoint = "CreateFileTransacted", CharSet = CharSet.Unicode, SetLastError = true)]
        protected static extern SafeFileHandle CreateFileTransacted(
               [In] String lpFileName,
               [In] SafeTransactionHandle.FileAccess dwDesiredAccess,
               [In] SafeTransactionHandle.FileShare dwShareMode,
               [In] IntPtr lpSecurityAttributes,
               [In] SafeTransactionHandle.FileMode dwCreationDisposition,
               [In] int dwFlagsAndAttributes,
               [In] IntPtr hTemplateFile,
               [In] SafeTransactionHandle txHandle,
               [In] IntPtr miniVersion,
               [In] IntPtr extendedOpenInformation
           );

        /// <summary>
        /// Importation de l&#039;interface KTM
        /// </summary>
        [ComImport]
        [Guid("79427A2B-F895-40e0-BE79-B57DC82ED231")]
        [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        protected interface IKernelTransaction
        {
            void GetHandle(out SafeTransactionHandle ktmHandle);
        }

        #endregion

        #endregion


        /// <summary>
        /// Copie un stream dans un autre
        /// de fa&ccedil;on asynchrone
        /// http://msdn.microsoft.com/fr-fr/magazine/cc337900.aspx
        /// </summary>
        /// <param name="source">Stream source</param>
        /// <param name="destination">Stream destination</param>
        /// <param name="completed">Action()</param>
        public static void CopyStreamToStream(FileStream source, FileStream destination,
                                              Action<FileStream, FileStream, Exception> completed)
        {
            byte[] buffer = new byte[0x1024];
            System.ComponentModel.AsyncOperation asyncOp = System.ComponentModel.AsyncOperationManager.CreateOperation(null);
          
            Action<Exception> done = e =>
            {
                if (completed != null) asyncOp.Post(delegate
                {
                    completed(source, destination, e);
                }, null);
            };

            AsyncCallback rc = null;
            rc = readResult =>
            {
                try
                {
                    int read = source.EndRead(readResult);
                    if (read > 0)
                    {
                        destination.BeginWrite(buffer, 0, read, writeResult =>
                        {
                            try
                            {
                                destination.EndWrite(writeResult);
                                source.BeginRead(
                                    buffer, 0, buffer.Length, rc, null);
                            }
                            catch (Exception exc) { done(exc); }
                        }, null);
                    }
                    else done(null);
                }
                catch (Exception exc) { done(exc); }
            };
            source.BeginRead(buffer, 0, buffer.Length, rc, null);
        }


        /// <summary>
        /// V&eacute;rifie qu&#039;un r&eacute;pertoire est vide
        /// </summary>
        /// <param name="path">Chemin de fichier du r&eacute;pertoire</param>
        /// <returns>bool</returns>
        public static bool DirectoryIsEmpty(string path)
        {
            return PathIsDirectoryEmpty(path);
        }


        #region Transactional methods

        /// <summary>
        /// Ecrit un fichier de fa&ccedil;on transactionnel
        /// </summary>
        /// <param name="data">Donn&eacute;es &agrave; &eacute;crire</param>
        /// <param name="path">Chemin du fichier dans lequel &eacute;crire les donn&eacute;es</param>
        /// <returns>Statut de l&#039;op&eacute;ration</returns>
        public static bool WriteFileTransacted(object data, string path)
        {
            if (data == null)
                return false;

            SafeTransactionHandle txHandle = null;
            SafeFileHandle fileHandle = null;
            bool response = true;
            try
            {
                IKernelTransaction kernelTx = (IKernelTransaction)TransactionInterop.GetDtcTransaction(System.Transactions.Transaction.Current);
                kernelTx.GetHandle(out txHandle);

                fileHandle
                    = CreateFileTransacted(
                        path
                        , SafeTransactionHandle.FileAccess.GENERIC_WRITE
                        , SafeTransactionHandle.FileShare.FILE_SHARE_NONE
                        , IntPtr.Zero
                        , SafeTransactionHandle.FileMode.CREATE_ALWAYS
                        , 0
                        , IntPtr.Zero
                        , txHandle
                        , IntPtr.Zero
                        , IntPtr.Zero);

                if (fileHandle.IsInvalid)
                    throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());

                using (FileStream stream = new FileStream(fileHandle, FileAccess.Write, 1024, false))
                {
                    BinaryFormatter writer = new BinaryFormatter();
                    writer.Serialize(stream, data);
                    stream.Close();
                }
            }
            catch
            {
                System.Transactions.Transaction.Current.Rollback();
                response = false;
            }
            finally
            {
                if (fileHandle != null &amp;&amp; !fileHandle.IsInvalid)
                {
                    fileHandle.Close();
                    fileHandle.Dispose();
                }

                if (txHandle != null &amp;&amp; !txHandle.IsInvalid)
                {
                    txHandle.Close();
                    txHandle.Dispose();
                }
            }
            return response;
        }


        /// <summary>
        /// Lit un fichier de fa&ccedil;on transactionnel
        /// </summary>
        /// <param name="path">Chemin du fichier &agrave; lire</param>
        /// <returns>Donn&eacute;es lu</returns>
        public object ReadFileTransacted(string path)
        {
            if (!File.Exists(path))
                return null;

            SafeTransactionHandle txHandle = null;
            SafeFileHandle fileHandle = null;
            object raw = null;
            try
            {
                IKernelTransaction kernelTx = (IKernelTransaction)TransactionInterop.GetDtcTransaction(System.Transactions.Transaction.Current);
                kernelTx.GetHandle(out txHandle);

                fileHandle
                    = CreateFileTransacted(
                        path
                        , SafeTransactionHandle.FileAccess.GENERIC_READ
                        , SafeTransactionHandle.FileShare.FILE_SHARE_READ
                        , IntPtr.Zero
                        , SafeTransactionHandle.FileMode.OPEN_ALWAYS
                        , 0
                        , IntPtr.Zero
                        , txHandle
                        , IntPtr.Zero
                        , IntPtr.Zero);

                if (fileHandle.IsInvalid)
                    throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());

                using (FileStream stream = new FileStream(fileHandle, FileAccess.Read, 1024, false))
                {
                    BinaryFormatter reader = new BinaryFormatter();
                    raw = reader.Deserialize(stream);
                }
            }
            catch
            {
                raw = null;
            }
            finally
            {
                if (fileHandle != null &amp;&amp; !fileHandle.IsInvalid)
                {
                    fileHandle.Close();
                    fileHandle.Dispose();
                }

                if (txHandle != null &amp;&amp; !txHandle.IsInvalid)
                {
                    txHandle.Close();
                    txHandle.Dispose();
                }
            }
            return raw;
        }

        #endregion
    }
}

   
     


Gets a files' contents from an Url with NetworkCredential

image_pdfimage_print
   
 
/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

#endregion

namespace Utilities
{
    public static class FileManager
    {
        /// <summary>
        /// Gets a files&#039; contents
        /// </summary>
        /// <param name="FileName">File name</param>
        /// <param name="UserName">User name to log in</param>
        /// <param name="Password">Password to log in</param>
        /// <param name="OutputStream">The output stream of the file</param>
        /// <returns>a string containing the file&#039;s contents</returns>
        public static void GetFileContents(Uri FileName, string UserName, string Password, out Stream OutputStream)
        {
            WebClient Client = null;
            OutputStream = null;
            try
            {
                Client = new WebClient();
                Client.Credentials = new NetworkCredential(UserName, Password);
                OutputStream = Client.OpenRead(FileName);
            }
            catch
            {
            }
        }

    }
}

   
     


Gets a file's contents (Used primarily for text documents on an FTP)

image_pdfimage_print
   
 
/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

#endregion

namespace Utilities
{
    public static class FileManager
    {

        /// <summary>
        /// Gets a file&#039;s contents (Used primarily for text documents on an FTP)
        /// </summary>
        /// <param name="FileName">Name of the file (should include the server address)</param>
        /// <param name="UserName">User name to log in</param>
        /// <param name="Password">Password to log in</param>
        /// <returns>A string containing the file&#039;s contents</returns>
        public static string GetFileContents(Uri FileName, string UserName, string Password)
        {
            WebClient Client = null;
            StreamReader Reader = null;
            try
            {
                Client = new WebClient();
                Client.Credentials = new NetworkCredential(UserName, Password);
                Reader = new StreamReader(Client.OpenRead(FileName));
                string Contents = Reader.ReadToEnd();
                Reader.Close();
                return Contents;
            }
            catch
            {
                return "";
            }
            finally
            {
                if (Reader != null)
                {
                    Reader.Close();
                    Reader.Dispose();
                }
                if (Client != null)
                {
                    Client.Dispose();
                }
            }
        }
    }
}

   
     


Gets a files' contents from a Url and save to an OutputStream

image_pdfimage_print
   
 
/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

#endregion

namespace Utilities
{
    public static class FileManager
    {


        /// <summary>
        /// Gets a files&#039; contents
        /// </summary>
        /// <param name="FileName">File name</param>
        /// <param name="OutputStream">The output stream of the file</param>
        /// <returns>a string containing the file&#039;s contents</returns>
        public static void GetFileContents(Uri FileName,out Stream OutputStream)
        {
            WebClient Client = null;
            OutputStream = null;
            try
            {
                Client = new WebClient();
                OutputStream = Client.OpenRead(FileName);
            }
            catch
            {
            }
        }
    }
}