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 methods and the difficulties we face in a specific environment we often have the need to exchange public data files over the network for resource sharing, while protecting private data from unauthorized access, and easy to use and intuitive operation.
Ewedrive provides 1 GB of free storage space, but it does not limit the size of a single file.
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.
Onedump
The OneDump bucket is not limited in size, but a single file is only 5 MB in size and 10 files are transferred at the same time, which can be used to store documents and other things.
The advantage of a network hard disk, also known as a shared space, is a hard disk space on the server. Here, if you have sufficient permissions, you can operate on 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.
Network hard disk development: 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
Network hard disk development details and key technical points
1. View 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 =NewDataTable ();
- DataRow dr;
- // Create a data table structure
- Dt. Columns. Add (NewDataColumn ("Type", System. Type. GetType ("System. String")));// Type
- Dt. Columns. Add (NewDataColumn ("Name", System. Type. GetType ("System. String")));// Name
- Dt. Columns. Add (NewDataColumn ("Action", System. Type. GetType ("System. String")));// Operation
- Dt. Columns. Add (NewDataColumn ("Owner", System. Type. GetType ("System. String")));// Creator
- // Fill in data for each row
- Foreach(StringDInDirectory. GetFileSystemEntries (fullFolderPath )){
- Dr = dt. NewRow ();// Create a new row
- String[] Parts = d. Split (New Char[] {'\\'});
- StringTxt = 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
- IntPos = currFullPath. IndexOf ("NetHard");
- StringRelaUrl = 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] ="Download";
- }
- Else If(Directory. Exists (d )){// For folders
- Dr [0] ="Folder";// Type
- StringPassword = GetFolderPassword (d );// Obtain the folder password information
- IntType = GetFolderLimitType (d );
- If(Password! ="No") & (Type! = 1 ))
- Dr [2] ="Href = PasswordValidate. aspx? Path ="+ D +"> Seal";// Action
- Else
- Dr [2] ="Enter";// Action
- Dr [3] = GetFolderOwner (d );// Obtain the name of the folder creator.
- }
- Else
- Response. Write ("");
- Dt. Rows. Add (dr );// Add rows
- ReturnDt;// Return the data table
- }
2. Create folders and set Access Permissions
Enter a new folder name in the current path to create a new folder. net IO namespace class library Directory method to achieve this operation: Directory. createDirectory (string directory), string directory indicates the complete path of the new folder. By default, this method gives all users full read/write permissions for the new folder. You can manually create a root folder for network hard drive sharing and set the write permission. You can set the access permission by executing the "permission wizard" of "internet information service, you can set a password to specify whether to allow users to access the folder and whether to allow users to delete the folder. In addition, to manage these folders, You need to retain the relevant settings, such as the folder name, location, restricted operation type, password, and creator. Write the information to the XML file, and then perform operations on the folder by reading and writing the XML file.
- PublicVoidCreateXmlOrAddFrag (StringXmlFullPath,StringFolderFullPath,StringOwner,StringPassword,IntType ){
- XmlDocument xmlDoc =NewXmlDocument ();
- StringXml ="";
- String xmlNode ="<Character>";
- XmlNode + ="<Full Path>";
- XmlNode + = folderFullPath;
- XmlNode + ="</Full Path>";
- 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 it does not exist
- Xml ="<? Xml version = '1. 0' encoding = 'gb2312 '?> ";
- Xml + ="<Folder>";
- Xml + = xmlNode;
- Xml + ="</Folder>";
- XmlDoc. LoadXml (xml );
- XmlDoc. Save (xmlFullPath );// Store files
- }
- Else{// Add a new file segment if an xml storage file exists.
- XmlDoc. Load (xmlFullPath );
- XmlDocumentFragment docFrag = xmlDoc. CreateDocumentFragment ();// File Element Node
- DocFrag. InnerXml = xmlNode;
- XmlNode currNode = xmlDoc. DocumentElement;// Get the document root node
- CurrNode. InsertBefore (docFrag, currNode. FirstChild );// Insert a document clip
- XmlDoc. Save (xmlFullPath );// Store changed content
- }
- }
The fileFullPath parameter is the XML file path for storing Folder Information, folderFullPath is the path of this new folder, owner is the creator name, and password is the password, type indicates the type of the restricted operation. "0" indicates that the access is restricted, and "1" indicates that the deletion is restricted ). The program first checks whether the file storing the folder information exists. If the file does not exist, it dynamically creates the file. When creating a folder, you only need to add a document segment. Here, the reading and writing of XML files is implemented through the DOM of the Document Object Model. Because the XML file is not large here, the requirements for memory resources are not too high and the speed will be very fast.
3. Operations on files and folders
Operations on files include "Download" and "delete". Use the following statement to download files:
- Dr [2] ="<A href ="+ Url +"Target = _ blank"+"> Download </a>";// Create a connection address
The url is the server path corresponding to the specified file. You can use this link to locate the file on the server. The client can download the file to the local machine or open it on the server.
To Delete a File, use the method in the File class library of the. net io namespace: File. Delete (string filename); where filename is the complete path of the File.
If the folder is set to "restricted access" or "restricted deletion" during creation, the user will be asked for password verification when performing such an operation, the corresponding operation can be completed only after the verification is passed .. The Delete () method provided by the Directory class library of. NET can only Delete empty folders. Therefore, you need to clear the contents of the folder before you can complete this operation. Because the folder may contain folders, this operation is implemented by recursive calling:
- PublicVoidDelete Folder (StringDir)
- {
- For each (StringDInDirectory. GetFileSystemEntries (dir ))
- {
- If (File. Exists (d ))
- File. Delete (d );// Delete the objects directly
- Else
- Delete Folder (d );// Recursively Delete subfolders
- }
- Directory. Delete (dir );// Delete an empty folder
- }
The dir parameter is the complete path of the folder to be deleted. The program uses a loop statement to find the content in the folder. if the content is a file, it deletes the content directly. If the content is a folder, it recursively calls the method itself to delete the subfolders. After the folder is cleared, the deletion operation is completed.
4. File Upload
The class libraries HttpPostedFile and HttpFilesCollection provided by. NET can access the files uploaded to the server and control the File Upload process. The HttpPostedFile class encapsulates the file objects uploaded to the server. Its method and attributes provide access to the content and attributes of each file. The HttpFilesCollection class provides a container for multiple HttpPostedFile objects, the class that stores the data structure uploaded to the server. It is accessed from the HttpRequest object by using the Files attribute of the transferred file set.
1) Enctype, the encoding type of the client form, is set to the MIME format of multipart/form-data. submit the form using the HTTP post method:
- <Form id="form1" method="post" enctype="multipart/form-data/form-data" runat="server" >
2) The HttpInputFile control runs on the server. The setting method is as follows:
- <INPUT id="file Up" type="file" size="6" runat="server">
3) If you want to upload multiple Files, you can set multiple HttpInputFile controls and use HttpRequest. Files to obtain these Files respectively.
5. Track the "current path" Value
Because you need to jump between different folders, and the content of all folders is routed through the same page Default. ASPx to display. When sending a query string to call it, you can set a complete representation of the static variable implementation path: public static string currFullPath = "". When the current path changes, the path value is sent to this static variable, which is always stored in the current path value and used as the query string. The call display page is displayed: currFullPath = Request ["path"]. Therefore, use Response. Redirect ("Default. aspx? Path = "+ currFullPath) statement can always display the content in the current folder.
6. Environment configuration file Web. config Processing
In Chinese, you need to change the global settings encoding from the default "Utf-8" to "gb2312 ":
- <Globalization
- Request Encoding="gb2312"
- Response Encoding="gb2312"
- />
At the same time, considering that the file size set by default by Web. config may not meet the actual needs, you can modify the value of maxRequestLength to enlarge its scale as needed:
- <HttpRuntime maxRequestLength="500000">
- </httpRuntime>
Conclusion
Asp.net and XML are currently hot topics in network development and application, and are widely used in data transmission, Information Publishing, electronic payment, network security, and many other fields. The technology is used together for network hard disk development to share system resources, which not only meets users' basic needs and is easy to operate, but also effectively protects users' private data from unauthorized access, it is secure and easy to maintain. Therefore, this processing mode can be widely used in practical applications such as the document transmission system, online examination system, and news publishing system.
- Application of session storage mode in ASP. NET
- Set of methods for uploading and downloading files in ASP. NET
- Introduction to cookie read/write methods in ASP. NET
- Javascript operations in ASP. NET
- Introduction and implementation of Single Sign-On in ASP. NET2.0