There are several key points:
1. Use of the openFileDialog Control
What if you click the select button to select a local file?
Specifically, it can be divided into the following steps:
A. Create a Winform and draw the corresponding controls.
B. Find openFileDialog in the toolbox and drag it to the "SELECT FILE" button. The following effect is displayed:
In this case, openFileDialog is displayed at the bottom of the interface, instead of the interface. You can click the "select file" button to open a local file.
At the same time, the Click function of the "select file" Button needs to add the following lines of code:
DialogResult diaResult = this. openFile. ShowDialog (); if (diaResult = DialogResult. OK) {// information such as the file name can be obtained internally}
What if I get the file name and path information in the open path?
These attributes can be used to achieve the following:
A. the FileName attribute of the openFileDialog control is used to obtain the path information. The path information includes the file name and the file extension name.
For example: E: \ Work \ Vs \ TestEncryption \ encryption processing \ waiting for Encryption \ dead coast line .txt
B. What if I only want to get the file name "Dead coastline?
Path. GetFileNameWithoutExtension (pathName) can be used to implement this function. In this case, without the file extension name, the input parameter pathName is the Path information in.
So how can I obtain the file size and extension name after selecting the corresponding file? The following code can be implemented:
FileInfo fi = new FileInfo (pathName); filetype = fi. Extension; // file Extension name filesize = fi. Length; // The number of bytes of File Information
The openFileDialog control can be set to the initial open path in three ways:
1. The following two lines of code have the same effect (these two types ):
OpenFileSave. initialDirectory = "E: \ Work \ Vs \ TestEncryption \ encryption processing \ save the file"; openFileSave. initialDirectory = @ "E: \ Work \ Vs \ TestEncryption \ encryption processing \ save the file ";
You can also use the openFileDialog control to right-click the attribute.
One of the attributes is InitialDirectory, which is followed by E: \ Work \ Vs \ TestEncryption \ encryption processing \ files to be encrypted \ save. The effect is the same as that of the above two lines of code.
C. The following functions are used:
////// Read the file information in the execution path //////Specified path///Starting position, usually set to zero///Length of File Information///
Public static byte [] ReadFile (string filename, int start, int length) {byte [] btFile = null; using (FileStream fs = new FileStream (filename, FileMode. open, FileAccess. read, FileShare. read) {btFile = new byte [length]; fs. seek (start, SeekOrigin. begin); fs. read (btFile, 0, length);} return btFile ;}
// Convert the byte array to string public static string BytesToString (byte [] bt) {return Encoding. UTF8.GetString (bt );}
Note:
1. There are various types of C # encryption code on the Internet for your reference.
2. MD5 is not an encryption algorithm, but an Digest algorithm. The encryption algorithm is reversible, and the Digest algorithm is theoretically irreversible. If MD5 is an encryption algorithm, it is better to call it a super compression algorithm, because if you input a plaintext of any length to him, the result is a fixed length of 16, 32, 64.
3. Write encrypted information to a specified file. For details, refer to the function for recording text logs.
4. For details about how to use the ComBox control, refer to the ComBox control.