Upload files in WebServices

Source: Internet
Author: User
During the summer vacation, a pocketpc project involves uploading and downloading files, including text, images, and other things. It is implemented using WebServices and has written the following two methods: 1 Public   Static   Void Stringtofile ( String Sfilepath, String Sstring)
2 {
3 Filestream OUTFILE;
4 Byte [] Binarydata;
5 Binarydata = System. Convert. frombase64string (sstring );
6 OUTFILE =   New Filestream (sfilepath, filemode. Create, fileaccess. Write );
7 OUTFILE. Write (binarydata, 0 , Binarydata. Length );
8 OUTFILE. Close ();
9 }
10
11 Public   Static   String Filetostring ( String Sfilepath)
12 {
13 Filestream infile;
14 Byte [] Binarydata;
15 Infile =   New Filestream (sfilepath, filemode. Open, fileaccess. Read );
16 Binarydata =   New Byte [infile. Length];
17 Long Bytesread = Infile. Read (binarydata, 0 ,( Int ) Infile. Length );
18 Infile. Close ();
19 Return System. Convert. tobase64string (binarydata, 0 , Binarydata. Length );
20 }

The second method: filetostring (string sfilepath)
Parameter: file path
Purpose: encode the object into a string in base64 format.

The first method is stringtofile (string sfilepath, string sstring)
Parameter: the first parameter indicates the file path to be stored.
The second parameter is a base64 string encoded using the preceding method.

In this way, we can upload and download files in WebServices.

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.