And documents the end user is to deal, the folder is only used to facilitate the management. Upload and download files also become a "network drive" feature an important part of the design.
1, interface layout
This part of the main control functions involved in two: one is the (ID) for the WebFile the File Field control, used to visit the upload file path; the other is the (ID) for the btnUpLoad the Upload button, click it to complete files Upload.
2, code implementation
In the "Design" panel, double-click btnUpLoad button to add the event handler, the code is as follows:
private void BtnUpload_Click (object sender, System.EventArgs e)
(
if (WebFile.PostedFile.FileName =="")
(
Info.Text = "Please select file to upload";
return;
)
try
(
char [] spliter = ('\');
string [] FileName = WebFile.PostedFile.FileName.Split (spliter, 10);
string FullPath = CurrentPath + @ "" + FileName [FileName.Length-1];
/ / Generate the full file name
WebFile.PostedFile.SaveAs (FullPath); / / Save the file
LoadDir (CurrentPath); / / reload the current directory
)
catch
(
Info.Text = "Upload file failed, please contact the administrator";
)
)
Must first determine whether the user chose to upload files, this can be WebFile.PostedFile.FileName property to get. It must be explained: WebFile is a File Field control object, the control is HtmlInputFile class, HtmlInputFile.PostedFile method used to obtain client access to upload files.
In determining the user selects a file to upload, it has to be set on its path to upload. First of all, to get the file name. As the user is a full path to the client needs to use the Split () method by "/ /" separator to split the results stored in an array. Such as: "C: / / UserDir / / Chapter1 / / Ch1.doc" can be divided into four parts, the last part of (array of the last one) is the name of the file needed. In the above procedure, FileName [FileName.Length-1] for the user uploaded file name.
Can be uploaded after the upload path, where used PostedFile.SaveAs () method. After the completion of upload, call LoadDir () method can show just upload the file name.
Run-time click the "Browse" button to open the file dialog box appears. Selected file, click "OK" button to complete the file upload work.