The processing of this piece of file asp.net can be implemented on the drive, file, folder operation.
1, can obtain the information of the drive.
2, create a copy delete move open file.
3. Stream class reading and writing. Read and write text files, read and write binary files, etc.
4, the use of FileUpload control to achieve file upload operation.
Mainly talk about the use of FileUpload control.
Picture file upload.
. aspx file:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "FileUpload.aspx.cs" inherits= "FileUpload"%> <!
DOCTYPE htmlpublic "-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
C # code:
The public partialclass FileUpload:System.Web.UI.Page {private string uploaddirectory;//file saves the path string. protected void Page_Load (Objectsender, EventArgs e) {//default to save the file in uploads under the site root file Uploaddirectory = Path.Combine
(Request.physicalapplicationpath, "uploads");
//Upload file.
protected void Btnfileupload_click (Objectsender, EventArgs e) {//To determine whether a file is submitted.
if (myfileupload.postedfile.filename== "") {Lblinfo.text = "The file submitted is empty!") Please select the file you want to upload! ";}
else {//To determine whether the file is larger than 200KB.
if (myfileupload.postedfile.contentlength> 204800) {lblinfo.text = "file cannot exceed 200KB";
else {//Determine the type of file.
string extension = Path.getextension (myFileUpload.PostedFile.FileName); switch (extension.
ToLower ()) {case '. bmp ': Case '. gif ': case '. jpg ': break; Default:lblinfo.
Text = "File type is not *.bmp |*.gif|*.jpg";
return;
//Save the file in the path of our defined uploaddirectory variable in the Web server. FileName remains unchanged.
String Serverfilename= path.getfilename (myFileUpload.PostedFile.FileName);
String fulluploadpath= path.combine (uploaddirectory,serverfilename);
try {myFileUpload.PostedFile.SaveAs (Fulluploadpath);//File upload.
Lblinfo.text = "File:" + serverfilename;
Lblinfo.text + = "successfully uploaded";
Lblinfo.text + = Fulluploadpath; The catch (Exception e2) {Lblinfo.text = e2.
message;//upload file error message. }
}
}
}
}
Show:
If I "Upload" to you an apple, first of all to judge the "upload" is Apple, and then judge the address of the upload is not, if not your "pocket", do not give, wait until the "upload" success, you give me a note---lable (Apple uploaded successfully into the belly).
Through the final example to you, is not the ASP.net file upload has an image of the understanding, hope that through a series of previous articles to learn to master the ASP.net upload files help Oh.