FTP, Email, and "Network neighbors" are commonly used for file data transmission to a certain extent, but they are mainly for "point-to-point" transmission, it is impossible to meet the application requirements of "One space, Resource Interaction". This "Point-to-multiple" sharing mode requires another transmission path. Network hard disk is a good solution.
Common transmission modes and difficulties in specific environments
We often have the following application requirements: resources are shared by exchanging public data files over the network, protecting private data from unauthorized access, and using simple and intuitive operations. Our common file transmission methods include FTP, Email, and network neighbors. Among them, "Ftp" is the most powerful, but it is a little complex to use, a lot of settings are enough to let many people stop, especially when the number of users is unpredictable, user settings for special needs will be more complicated; "Email" is familiar to everyone, but its transmission requires you not only to connect to the Internet, but also its security is also a problem, within an enterprise, it is not a good way to exchange documents such as finance and labor resources. "Network neighbors" are another method for transferring documents, by specifying shared Web folders on the local machine and placing resource files, users within a certain range can access these files. However, this method is widely used, generally, users in the same DNS segment can access the domain name smoothly. Other users, especially those on the Internet, are difficult to use. In addition, similar to Email, the domain name is not intuitive, most of the time, you have to expand the search layer by layer on many list computers to obtain the resources you want!
From this point of view, although the above three methods have achieved the communication of file data to a certain extent, however, they are mainly oriented to "point-to-point" transmission (you can only passively wait for the other party to place data, rather than actively "Visually" requests), and cannot implement "one space, resource Exchange "application requirements, this" Point-to-multiple "based sharing method needs to seek another transmission channel, network hard disk is a good solution.
Advantages of network Hard Disks
A network hard disk (also called a shared space) is a hard disk space on the server. If you have sufficient permissions, you can operate it at will, just like using your local computer. You must know that all of this is transmitted over Http and displayed in front of all users in the form of Web. You can use a browser to access it. In this way, "a space, the sharing mode of resource mutual view is realized!
In addition, the network hard disk interface runs on the client. It allows users to submit data to the server and manage the information within the specified range. This processing mode is widely used in actual development, especially in the construction of an interactive network document management system: Online examination system, file transmission system, news and publishing system, and the company bidding system have a large number of applications!
The following uses Asp.net (implemented in Visual C #) and Xml (Extensible Markup Language) to develop such a network hard drive system. Detailed descriptions of program development details and Key Technologies and difficulties used in code are provided. You can develop your own network hard drive by referring to these instructions.
Functions of network Hard Disks
Our network hard drive provides the following features:
1. View folder content
2. You can set access permissions when creating a new folder.
3. jump between folders: Go to the next level and return to the previous level
4. upload a file to a specified folder
5. download the file to your local computer or view the file content online.
6. delete files or folders
Development details and key technical points
1. view the folder content:
At the beginning, the program will enter the specified root folder (such as NetHard). The content in this folder will be displayed in the list through the data binding control (DataGrid), including the following: category (difference folder or file), name, permission (whether to allow access to the folder? Can an object be downloaded ?) , Delete (Are you allowed to delete files or folders ?) And the creator of the folder. Here, because the content in the folder changes dynamically (you Don't know when a user transfers files, creates folders, or deletes them ), we dynamically create a data table able to read the content in the specified folder and bind it to the display control DataGrid as a data source. In this way, data display is always timely. The function for creating a dynamic table is as follows:
Public DataTable Bind (string fullFolderPath) // create a data table to read the folder content
{
// The following describes how to dynamically create a data table:
DataTable dt = new DataTable ();
DataRow dr;
// Create a data table structure
Dt. Columns. Add (new DataColumn ("type", System. Type. GetType ("System. String"); // type
Dt. Columns. Add (new DataColumn ("name", System. Type. GetType ("System. String"); // name
Dt. Columns. Add (new DataColumn ("action", System. Type. GetType ("System. String"); // operation
Dt. Columns. Add (new DataColumn ("owner", System. Type. GetType ("System. String"); // creator
// Fill in data for each row
Foreach (string d in Directory. GetFileSystemEntries (fullFolderPath )){
Dr = dt. NewRow (); // create a new row
String [] parts = d. Split (new char [] {\});
String txt = parts [parts. Length-1]; // obtain the last part of the string, which may be a file name or folder
Dr [1] = txt; // name
If (File. Exists (d) // if it is a File
{
Dr [0] = "file"; // type
Int pos = currFullPath. IndexOf ("NetHard ");
String relaUrl = currFullPath. Substring (pos );
String
Url = "http: // 10.80.50.1/SharedSpace/" + relaUrl + "/" + txt ;//
10.80.50.1 is the author's server address. You should modify it to your server address.
Dr [2] = "<a href =" + url + "target = _ blank" + "> download </a> ";
}
Else if (Directory. Exists (d) {// if it is a folder
Dr [0] = "folder"; // type
String password = GetFolderPassword (d); // get the folder password information
Int type = GetFolderLimitType (d );
If (password! = "No") & (type! = 1 ))
Dr [2] = "<
Href = PasswordValidate. aspx? Path = "+ d +"> seal </a> "; // action
Else
Dr [2] = "<a href = Default. aspx? Path = "+ d +"> enter </a> "; // action
Dr [3] = GetFolderOwner (d); // get the name of the folder creator
}
Else
Response. Write ("<script> alert (no object can be bound !) </Script> ");
Dt. Rows. Add (dr); // Add a row
Return dt; // return data table
}
}
This method extracts the content in the specified folder for processing separately: if it is a file, the "Download" link is displayed pointing to the Url of the file on the server; the folder needs to be further differentiated depending on whether the folder is protected or not and the Protection Type: If "restricted access" is displayed, "sealed" is imported to the password verification page. When "not restricted access" is entered, the query string is modified, the show "go" link points to the initial display page.
2. Create a new folder and set access permissions:
After entering the new folder name, you can create a new folder in the current path. The remote creation of a new folder in Asp.net is exactly the same as the local machine operation, which is very simple ,. net IO namespace provides a dedicated class library Directory, which can be implemented by calling its method. The statement is as follows:
Directory. CreateDirectory (string directory)
Specifically, the string directory indicates the complete path of the new folder. By default, this method opens full read/write permissions for the new folder to all users. In special cases, you can also manually create the root folder shared by the Network hard disk (the "NetHard" folder in the program, you can change it, you need to manually set the write permission for this folder. Under IIS, you can run the "permission wizard" on this folder under "internet Information Service" to set the access permission.
Security should be considered during resource sharing. Here, you can set the user's access permission to the folder. By setting the password, you can specify whether to allow the user to enter the folder, whether to allow the user to delete the folder, or both. In this way, you can protect your files, exclusively access them, or restrict them to a specific range (members in this range should know your password). In this way, the product R & D department can share one folder, and the finance department can share another folder in the same way. People who do not belong to this department will be restricted. Of course, you can also apply this restriction to a single file (there seems to be not many such applications, and the program is not implemented ).
In addition, to manage these folders, you need to keep their settings: folder name, location, restricted operation type, password, and creator. The program writes the information into an Xml file (this is folder. and then perform various management operations on the folder by reading and writing the xml file. The following method implements the storage of information set when creating a folder:
Public void CreateXmlOrAddFrag (string xmlFullPath, string
FolderFullPath, string owner, string password, int type ){
XmlDocument xmlDoc = new XmlDocument ();
String xml = "";
String xmlNode = "<character> ";
XmlNode + = "<fullPath> ";
XmlNode + = folderFullPath;
XmlNode + = "</fullPath> ";
XmlNode + = "<owner> ";
XmlNode + = owner;
XmlNode + = "</owner> ";
XmlNode + = "<password> ";
XmlNode + = password;
XmlNode + = "</password> ";
XmlNode + = "<type> ";
XmlNode + = type;
XmlNode + = "</type> ";
XmlNode + = "</character> ";
If (! File. Exists (xmlFullPath) {// create an xml storage File if the File does not exist
Xml = "<? Xml version = 1.0 encoding = gb2312?> ";
Xml + = "<folder> ";
Xml + = xmlNode;
Xml + = "</folder> ";
XmlDoc. LoadXml (xml );
XmlDoc. Save (xmlFullPath); // stores files
}
Else {// If an xml storage file exists, add a new file segment.
XmlDoc. Load (xmlFullPath );
XmlDocumentFragment
DocFrag = xmlDoc. CreateDocumentFragment (); // File Fragment Element Node
DocFrag. InnerXml = xmlNode;
XmlNode currNode = xmlDoc. DocumentElement; // obtain the root node of the document.
CurrNode. InsertBefore (docFrag, currNode. FirstChild); // insert a document segment
XmlDoc. Save (xmlFullPath); // Storage Change
}
}
The fileFullPath parameter is the xml file path for storing Folder Information, folderFullPath is the path of the new folder, owner is the creator name, and password is the password, type indicates the type of the operation to be restricted ("0" indicates restricted access, "1" indicates restricted deletion ). At the beginning of the program, the folder. xml file storing folder Information may not exist.