C # Get selection file information
private bool Getdocucontent (out byte[] Content, out string FileName, out string extensionname) {Long Ma Xlength = 10485760; Content within 10M = null; ExtensionName = string. Empty; FileName = string. Empty; OpenFileDialog Vsopenfiledialog = new OpenFileDialog (); Vsopenfiledialog.initialdirectory = "d:\\"; Vsopenfiledialog.filter = "All Files (*. *) |*.*"; Vsopenfiledialog.filterindex = 0; Vsopenfiledialog.multiselect = false; try {if (vsopenfiledialog.showdialog () = = DialogResult.OK) { Path.getextension method: Returns the extension of the specified path string extensionname = Path.getextension (vsopenfiledialog.filename); Path.getfilename method: Returns the file name and extension of the specified path string. FileName = Path.getfilename (vsopenfiledialog.filename); FileInfo vsfileinfo = new FileInfo (vsopenfiledialog.filename); if (Vsfileinfo.length > MaxLength) {MessageBox.Show ("File Extra long! "); return false; }//vsfileinfo.openread method:creates a read-only FileStream. FileStream FileStream = Vsfileinfo.openread (); if (Filestream.length = = 0) {MessageBox.Show ("Empty file! "); return false; } Content = new byte[filestream.length]; int Size = FileStream.Read (Content, 0, Convert.ToInt32 (filestream.length)); Filestream.close (); return true; } return false; } catch (Exception ex) {return false; } }
Small bet
1. C # Winform OpenFileDialog controls
2. C # FileStream.Read Method
If the selected file 1111.png, is the tracking content display:
ExtensionName = Path.getextension (vsopenfiledialog.filename)
FileName = Path.getfilename (vsopenfiledialog.filename)
FileInfo vsfileinfo = new FileInfo (vsopenfiledialog.filename)
Content = new Byte[filestream.length]
4, if the relative return of byte[] Content encryption, you can use: convert.tobase64string (Content), the function's return value, is still: byte[] type.
The above is C # to get the content of select file information, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!