Upload and download files through Web Services

Source: Internet
Author: User

With the development of Internet technology and the increasing demand for cross-platform Services, Web Services is widely used. We need to pass string information through Web Services and binary file information. Next, we will introduce how to download files from the server to the client through Web Services and upload files from the client to the server through Web Services.
1. Display and download files through Web Services
The Web Services created here are named GetBinaryFile, which provides two common methods: GetImage () and GetImageType (). The former returns the binary file byte array, and the latter returns the file type, the GetImage () method has a parameter used to select the name of the file to be displayed or downloaded on the client. The files we show and downloaded here can not be in the virtual directory. The advantage of this method is that the files can be displayed and downloaded according to the permissions. We can see from the following method that, the actual file location is not in the virtual directory, so you can better control the permissions of the file, which is particularly useful for high security. This function can be implemented using Stream objects in the previous ASP program. To facilitate testing, all the source code is listed and described and commented out in the source code.
First, create the GetBinaryFile. asmx file:
We can. create a C # aspxWebCS project in. NET, add a new project, select "Web service", and set the file name to GetBinaryFile. asmx: Enter the following code in "view code": GetBinaryFile. asmx. cs:
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Diagnostics;
Using System. Web;
Using System. Web. UI;
Using System. Web. Services;
Using System. IO;
Namespace xml.sz.luohuedu.net. aspxWebCS
{
/// <Summary>
/// Summary of GetBinaryFile.
/// Web Services Name: GetBinaryFile

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.