File processing Asp.net can operate on drives, files, and folders.

1. You can get the drive information.

2. Create copy delete move open files.

3, stream read and write. Read and write text files,Read and write binary files, etc.

4. Use the fileupload control to implement file upload operations.

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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <form runat="server">
 <asp:fileuploadidasp:fileuploadid="myfileupload" runat="server" />
 <asp:label runat="server"></asp:label>
 <br />
 <asp:buttonidasp:buttonid="btnfileupload" runat="server" onclick="btnfileupload_click"
 text="upload file" />


public partialclass fileupload:system.web.ui.page
 private string uploaddirectory;//File save path string.
 protected void page_load (objectsender, eventargs e)
 //Save the file in the uploads under the site root file by default
 uploaddirectory=path.combine (request.physicalapplicationpath, "uploads");
 //upload files.
 protected void btnfileupload_click (objectsender, eventargs e)
 //Determine if there are any files submitted.
 if (myfileupload.postedfile.filename == "")
  lblinfo.text="The file submitted is empty! Please choose a file to upload!";
  //Determine if the file size exceeds 200kb.
  if (myfileupload.postedfile.contentlength>204800)
  lblinfo.text="File cannot exceed 200kb";
  //Judge the file type.
  string extension=path.getextension (myfileupload.postedfile.filename);
  switch (extension.tolower ())
   case ".bmp":
   case ".gif":
   case ".jpg":
   lblinfo .text="File type is not * .bmp | * .gif | * .jpg";
  //Save the file in the web server under the path of the uploaddirectory variable we defined.
  //The file name remains unchanged.
  string serverfilename=path.getfilename (myfileupload.postedfile.filename);
  string fulluploadpath=path.combine (uploaddirectory, serverfilename);
   myfileupload.postedfile.saveas (fulluploadpath);//File upload.
   lblinfo.text="File:" + serverfilename;
   lblinfo.text +="Uploaded successfully";
   lblinfo.text +=fulluploadpath;
  catch (exception e2)
   lblinfo.text=e2.message;//Upload file error message.


If I "upload" you an apple,The first thing to judge is "upload" is Apple,Then judge whether the uploaded address is correct.If it's not your "pocket", don't give it, wait until "upload" is successful, and you will give me a note --- lable (Apple has successfully uploaded it)

  • Previous asp + jsp + JavaScript dynamically add data rows
  • Next Method for implementing mobile phone vibration setting in Android