Implementation Analysis of asp.net network Hard Disk

Source: Internet
Author: User

The so-called "Network hard disk" means to provide the disk space of the server to users. Users can upload, download, and delete files and create and delete folders on the Internet. You can also share files over the Internet. The actual requirement is to access, create, and delete system files or folders on the server on the client.

Functional requirements for network hard disks:

● User logon, logout, and user registration

● Create a folder and upload a file

● View File Attributes (including name, directory, type, size, and Creation Time)

● Delete an object

● Change the file icon (divided into large icons and small icons)

● Search for your own files and download them

A user name and password are required to access the file, effectively protecting the confidentiality of the file.

The development of network hard disks is actually very simple. It mainly uses class library I/O to perform file operations and maps the database to the physical path, here are some of the main points:

The first is the database design. We designed the most suitable database based on our own needs. The database we designed is divided into three tables: T_User, T_FileType, T_FileInfo

T_User

T_FileType

T_FileInfo

Secondly, we know that the network hard disk meets the needs of many users, so each user has its own space, which requires us to use the login and registration functions on the page, we need to allocate space for the corresponding user during registration. We recommend that you do not directly use the login name for the name. You can map the name, for example, the user name is admin, the directory name of the physical path can be adminDir, adminFile, and so on, mainly from the security aspect. After the user is registered, several initial folders will be displayed in the physical space.

The following are the operations on files.

File Operations must first ensure the consistency between the database and the physical path. For example, if a file is added, the physical path is added, and the database must add records accordingly, there is no big problem. Here we will post the downloaded code:

Copy codeCode: private void FileDownload (string FullFileName) // download
{
FileInfo DownloadFile = new FileInfo (FullFileName); // you can specify the object to be downloaded.
Response. Clear (); // Clear all content output in the buffer stream
Response. ClearHeaders (); // clear all headers in the buffer stream
Response. Buffer = false; // set the Buffer output to false.
// Set the http mime type of the output stream to application/octet-stream
Response. ContentType = "application/octet-stream ";
// Add the HTTP header to the output stream
Response. AppendHeader ("Content-Disposition ",
"Attachment; filename =" +
HttpUtility. UrlEncode (DownloadFile. FullName. Substring (FullFileName. LastIndexOf ("\") + 1 ),
System. Text. Encoding. UTF8 ));
Response. AppendHeader ("Content-Length", DownloadFile. Length. ToString ());
// Write the specified file directly to the HTTP Content output stream.
Response. WriteFile (DownloadFile. FullName );
Response. Flush (); // send the Current Buffer output to the client
Response. End (); // send all current buffered output to the client
}

The modification is similar to the transfer logic. When you modify the directory name, you create a new directory, move it to the new directory through the subdirectory, and recursively modify the path name of the subdirectory and file in the database, modifying the file is simpler, and the transfer is also the case...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.