Asp.net+xml Development Network hard Disk (ii) __.net

Source: Internet
Author: User
Tags data structures http post

3, the operation of files and folders:

Actions on a file include "Download" and "delete", and when the list shows the contents of the specified folder, there are statements for the file:

dr[2]= "<a href=" +url+ "Target=_blank" + "> Download </a>";//Establish a join address

Where the URL is the server path for the specified file. Navigate the file to the corresponding location on the server with such a link. Depending on the format of the file, the client can download the file to the computer, or it can be opened on the server.

Deleting the file is simple. NET's IO namespace, there is a method for the File class library:

File.delete (string filename), where filename is the full path of the file

You need to be aware that the deletion of the file will not need to be validated, to prevent the file from being deleted, you need to follow the following way. (Of course, in the program to avoid the deletion of files to provide validation verification, folder deletion is the same.) )

The operation of the folder is divided into: Enter or delete. If a folder is set to "enter restricted" or "delete restricted" when it is created, the user will be required to authenticate the password when performing such an operation, which protects your files from being illegally accessed or deleted.

The deletion of the folder is slightly more complicated than the deletion of the file. NET Directory Class Library provides methods delete () can only delete empty folders, which requires us to first empty the contents of the folder before we can complete this operation, because the folder may also contain folders, we do this by recursive call to achieve this action:

Ways to delete a folder
public void DeleteFolder (string dir)
{
foreach (String D in Directory.getfilesystementries (dir))
{
if (file.exists (d))
File.delete (d);//delete files directly from them
Else
DeleteFolder (d);//recursively Delete subfolders
}
Directory.delete (dir);//Delete empty folder
}

Where the parameter dir is the full path to the folder you want to delete. The program uses a looping statement to find the contents of the folder, the file is deleted directly, if it is a folder, then recursively call the method itself to delete the subfolder, the folder empty and then complete the delete operation.

4, File Upload:

To achieve the function of the network hard disk, there must be files available for operation, which are uploaded from the client (of course, the server side can provide these files, but this is not the focus of the network hard disk), in the past we implemented the file upload, in the ASP is usually using the first file upload components, such as Microsoft Postingacceptor components, plus some of the paid components provided by third parties (but really, these components are not working). At that time wanted to develop such a file upload component, quite cumbersome; NET provides the class libraries Httppostedfile and httpfilescollection can easily access files uploaded to the server, while allowing developers to control the file upload process. The Httppostedfile class encapsulates a file object that has been uploaded to the server, whose methods and properties provide access to the contents and properties of each file, and the Httpfilecollection class provides a container for multiple Httppostedfile objects. Used as a class to save data structures to the server, so you can take advantage of the transferred collection of files that can be accessed from the HttpRequest object through its Files property, which can be accessed once the server receives the entire content of the request. These built-in components make it easy to implement file uploads in ASP.net, or even a few lines of code. About asp.net in the implementation of file upload a lot of articles, here do not make a special exposition, you can refer to those articles, here, only tips you need to pay attention to the following points:

1), the encoding type of the client form enctype set to multipart/form-data MIME format, submit the form using the HTTP POST method, as follows:

<form id= "Form1" method= "Post" enctype= "Multipart/form-data/form-data"
runat= "Server" >

2), Httpinputfile control run on the server side, set the Runat=server,type=file, as follows:

<input id= "Fileup" type= "File" size= "6" runat= "Server" >

3, to upload multiple files, you can lay out multiple httpinputfile controls, and then use Httprequest.files to obtain these files.

5, the Environment configuration file Web.config processing:

In the Chinese state, you may need to change the globalization settings encoding from the default "Utf-8" to "gb2312", which is as follows:

<globalization
Requestencoding= "gb2312"
Responseencoding= "gb2312"
/>

Also, the file size limit web.config by default may not meet your needs, and you may need to magnify the limits. This is done by modifying the value of the parameter maxRequestLength, as follows:

<!--set the maximum number of bytes that can be accepted-->

6, at any time to track the "Current Path" value:

Another key point in the program is about "current path", because you always need to jump between different folders: Click "Enter" to reach the next level folder, click "Top Folder" to return to the previous level folder, and all of these folders are displayed through the same page (Default.aspx) , this display page is set to always display the contents of the current folder. When you send a query string to invoke it, you need to include a full representation of the current path in the query string, which is implemented by setting a static variable in the program: public static string Currfullpath= ""; This path value is always passed to this static scalar: currfullpath=request["path"; This allows the static variable to always store the current path value, with this static variable calling the display page for the query string: Response.Redirect (" Default.aspx?path= "+currfullpath" will always display the contents of the current folder.

Resources:

"ASP.net Programmer's Reference manual", "Advanced XML Programming", "C # Advanced Programming", Microsoft MSDN

Operating Environment:

Program in: Windows XP Chinese official edition,. Net Frameworks official version, Visual Studio.NET Chinese version of the debugging through, in the LAN (Headquarters + multiple off-site subsidiary mode) on the stable operation

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.