C# Image to Byte Array and Byte Array to Image Converter Class



public Image byteArrayToImage(byte[] byteArrayIn)
{
    MemoryStream ms = new MemoryStream(byteArrayIn);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
}

Image to Byte Array and Byte Array to Image Converter Class




public byte[] imageToByteArray(System.Drawing.Image imageIn)

{

    MemoryStream ms = new MemoryStream();

    imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);

    return ms.ToArray();

}

Get associated icon from file



public enum IconSize
{
    Small,
    Large
}
public class IconExtractor
{
    private const uint SHGFI_ICON = 0x100;
    private const uint SHGFI_LARGEICON = 0x0;
    private const uint SHGFI_SMALLICON = 0x1;
    [StructLayout(LayoutKind.Sequential)]
    private struct SHFILEINFO
    {
        public IntPtr hIcon;
        public IntPtr iIcon;
        public uint dwAttributes;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szDisplayName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
        public string szTypeName;
    };
    [DllImport("shell32.dll")]
    private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
    public IconExtractor()
    {
    }
    public System.Drawing.Icon Extract(string File, IconSize Size)
    {
        IntPtr hIcon;
        SHFILEINFO shinfo = new SHFILEINFO();
        if (Size == IconSize.Large)
        {
            hIcon = SHGetFileInfo(File, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_LARGEICON);
        }
        else
        {
            hIcon = SHGetFileInfo(File, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
        }
        return System.Drawing.Icon.FromHandle(shinfo.hIcon);
    }
    public System.Drawing.Icon Extract(string File)
    {
        return this.Extract(File, IconSize.Small);
    }
}

GET COMPUTER NAME



public List GetComputersOnNetwork()
{
    List list = new List();
    using (DirectoryEntry root = new DirectoryEntry("WinNT:"))
    {
        foreach (DirectoryEntry computers in root.Children)
        {
            foreach (DirectoryEntry computer in computers.Children)
            {
                if ((computer.Name != "Schema"))
                {
                    list.Add(computer.Name);
                    comboBox1.Items.Add(computer.Name );
                }
            }
        }
    }
    return list;
}