Upload program written in asp.net

Source: Internet
Author: User

<% -- <Br>
Upload. aspx <br>
This is an upload file, from which we can see the advantages of asp.net, the previously required controls to complete the program, now only a few lines of code can be easily completed. <Br>
-- %> <Br>
<% @ Import Namespace = "System. IO" %> <br>
<% @ Page Language = "C #" debug = "true" codepage = "936" %> <br>
<Br>
<Html> <br>
<Head> <br>
<Title> file upload, aspcool.com </title> <br>
<Script language = "C #" runat = "server"> <br>
<Br>
Public void UploadFile (object sender, EventArgs E) <br>
{<Br>
<Br>
If (myFile. PostedFile! = Null) <br>
{<Br>
// Define some variables <br>
String nam = myFile. PostedFile. FileName; <br>
Int I = nam. LastIndexOf ("\"); <br>
String newnm = nam. Substring (I); <br>
<Br>
<Br>
// Change the following "c: \" to the address you want to save. <Br>
MyFile. PostedFile. SaveAs ("c: \" + newnm); <br>
<Br>
// Obtain the attributes of the uploaded file. <Br>
Fname. Text = myFile. PostedFile. FileName; <br>
Fenc. Text = myFile. PostedFile. ContentType; <br>
Fsize. Text = myFile. PostedFile. ContentLength. ToString (); <br>
<Br>
<Br>
} <Br>
} <Br>
<Br>
</Script> <br>
</Head> <br>
<Body> <br>
<Center> <br>
<H3> File Upload demonstration, flying e production <Form id = "uploderform" method = "post" action = "upload. aspx" enctype = "multipart/form-data" runat = "server"> <br>
<Br>
<Table border = "1" cellspacing = "0" cellpadding = "0"> <br>
<Tr> <td> <Tr> <td> <br>
<Input type = "file" id = "myFile" runat = "server"> <br>
</Td> </tr> <br>
<Tr> <td> <br>
<Input type = "button" value = "Upload" OnServerClick = "UploadFile" runat = "server"> <br>
</Td> </tr> <br>
</Table> <br>
</Form> <br>
<Br>
<Br>
<Table border = "1" cellspacing = "0"> <br>
<Tr> <td> <B> documents </B> </td> <br>
<Td> </td> <br>
</Tr> <br>
<Tr> <br>
<Td> file name: </td> <br>
<Td> <asp: label id = "fname" text = "" runat = "server"/> </td> </tr> <br>
<Tr> <br>
<Td> file type: </td> <br>
<Td> <asp: label id = "fenc" runat = "server"/> </td> </tr> <br>
<Tr> <br>
<Td> file size: (in bytes) </td> <br>
<Td> <asp: label id = "fsize" runat = "server"/> </td> </tr> <br>
</Table> <br>
<Br>
<Br>
<Br>
<H5> you can download this program from <a href = "http://www.aspcool.com/download"> http://www.aspcool.com/download </a>. We will provide you with more programs. If you have any comments please go to my <a href = "http://www.chaxiu.com/club/right.php? Boardid = 7 & page = 1 "> ASP Forum </a>. </H5> <br>
</Center> <br>
</Body> <br>
</Html> <br>

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.