Subscribe to web2feel.com
Subscribe to web2feel.com

Read ini File

Diposting oleh Unknown Selasa, 28 Juni 2016 0 komentar

private string[] getStringIni()
{
   var dir = Directory.GetCurrentDirectory() + @"\SETTINGS.ini";
   var txt1 = File.ReadLines(dir).ToArray();
   return txt1;
}

Encrypt File / Decrypt File

Diposting oleh Unknown 0 komentar

using System.IO;
using System.Security.Cryptography;

private readonly string Key=@"MyKey";
private void EncryptFile(string inputFile, string outputFile)
        {
            try
            {
                // Your Key Here
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(Key);
                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
                RijndaelManaged RMCrypto = new RijndaelManaged();
                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateEncryptor(key, key),
                    CryptoStreamMode.Write);
                FileStream fsIn = new FileStream(inputFile, FileMode.Open);
                int data;
                while ((data = fsIn.ReadByte()) != -1)
                    cs.WriteByte((byte)data);

                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
            catch
            {
                XtraMessageBox.Show("Encryption failed!", "Error");
            }
        }
       
        ///<summary>
        /// Decrypts a file using Rijndael algorithm.
        ///</summary>
        ///<param name="inputFile"></param>
        ///<param name="outputFile"></param>
       
private void DecryptFile(string inputFile, string outputFile)
        {
            {
                 // Your Key Here
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(Key);
                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
                RijndaelManaged RMCrypto = new RijndaelManaged();
                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, key),
                    CryptoStreamMode.Read);
                FileStream fsOut = new FileStream(outputFile, FileMode.Create);
                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);
                fsOut.Close();
                cs.Close();
                fsCrypt.Close();
            }
        }

using System.Security.Cryptography;
private static readonly string Key = "Mykey";
        public static string Encrypt(string clearText)
        {
           
            byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(Key, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(clearBytes, 0, clearBytes.Length);
                        cs.Close();
                    }
                    clearText = Convert.ToBase64String(ms.ToArray());
                }
            }
            return clearText;
        }


        public static string Decrypt(string cipherText)
        {
          
            byte[] cipherBytes = Convert.FromBase64String(cipherText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(Key, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(cipherBytes, 0, cipherBytes.Length);
                        cs.Close();
                    }
                    cipherText = Encoding.Unicode.GetString(ms.ToArray());
                }
            }
            return cipherText;
        }

Row Color in Grid Control C#

Diposting oleh Unknown 0 komentar

private void gridView1_RowStyle(object sender, RowStyleEventArgs e)
        {
            var view = sender as GridView;
            if (e.RowHandle < 0) return;
            var str = view.GetRowCellDisplayText(e.RowHandle, view.Columns["last_login"]);
            if (!string.IsNullOrEmpty(str))
            {
               if (str== DateTime.Now)
                {
                   
                    e.Appearance.BackColor = Color.Blue;
                    e.Appearance.BackColor2 = Color.White;
                }
            }
           
        }

private void gridView1_RowStyle(object sender, RowStyleEventArgs e)
        {
            var view = sender as GridView;
            if (e.RowHandle < 0) return;
            var str = view.GetRowCellDisplayText(e.RowHandle, view.Columns["last_login"]);
            if (!string.IsNullOrEmpty(str))
            {
                if (str== DateTime.Now)
                {                   
                    e.Appearance.ForeColor = Color.Blue;
                }
            }
           
        }