Www.chinacs.net 2001-8-13 Chinese C # Technology Station
Get file properties in ASP.NET (RETRIEVING FILE Information In ASP.NET)
By Steven Smith
Using ASP.NET We can easily get information about files, including: file name, path, extension, size, and creation and date of use. Below, we take a look at how to obtain the information about the file.
If we use a typical ASP to get file information, it must use the .filesystemobjiect script object to query the information about the file. But in ASP.NET, .filesystemObject is replaced by System.io namespace, in .system.io, it contains a lot of classes that get file system information. One of the classes is Fileinfo, which has information about documents we want to know at any time. Using this class (original use of object), we can completely get many of the information (here, we use the file itself). And using FileInfo can also complete other operations for files, such as backup, rename, and more.
According to the practice, let's see the code first:
FileInfo.aspx <% @ page language = "c #"%>
Protected system.io.fileinfo objfi; protected string filename;
Protected void page_load () {if (! ispostback) {// get file path filename = request.servervariables ["path_translated"];
// Create an Objfi object objfi = new system.io.fileinfo (filename);
// File information fullname.text = objfi.fullname; name.text = objfi.name; size.text = objfi.length.tostring (); created.text = objfi.creationTime.tostring (); access.text = Objfi. LastAccessTime.ToString (); modified.Text = objFI.LastWriteTime.ToString (); directory.Text = objFI.DirectoryName; extension.Text = objFI.Extension;}} script>
head> head>