System.IO.FileInfo.Encrypt C# (CSharp) Method

Encrypt() public method

public Encrypt ( ) : void
return void
        public void Encrypt()
        {
            File.Encrypt(FullPath);
        }

Usage Example

        private void encryptFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(this.openFileDialog1.FileName);

            if(!fi.Exists)
            {
                MessageBox.Show("File Not Found");
                return;
            }

            if(fi.Attributes.ToString().Contains(FileAttributes.Encrypted.ToString()))
            {
                MessageBox.Show("File is already encrypted");
                return;
            }

            if(MessageBox.Show("Are you sure you want to encrypt this file?\n\nOnly this user will be able to decrypt","File Peeker",MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                fi.IsReadOnly = false;

                try
                {
                    fi.Encrypt();
                    fi.Refresh();
                    getFileInfo(fi);
                }catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
All Usage Examples Of System.IO.FileInfo::Encrypt