O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Upload or Download Large Binary Data

Problem

You want to transfer an image or a file to or from a Web service.

Solution

Submit or return the data as a byte array.

Discussion

Web services support only a carefully limited set of data types, an approach that’s designed to ensure optimum cross-platform compatibility. However, you can transmit virtually anything if you convert it to binary first.

The following Web service accepts a byte array and saves it directly to disk. For this code to work, the ASP.NET process must have privileges to write to the appropriate directory. You should also import the System.IO namespace.

<WebService()> _ Public Class UploadData Inherits System.Web.Services.WebService <WebMethod()> _ Public Sub UploadFile(ByVal originalName ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required