WebService uploads images

Source: Internet
Author: User

 

Code
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. Web;
Using System. Web. Services;
Using System. IO;

Namespace Webapplication1
{
///   <Summary>
/// Upfile Summary
///   </Summary>
[WebService (namespace =   " Http://tempuri.org/ " )]
[Webservicebinding (conformsto = Wsiprofiles. basicprofile1_1)]
[System. componentmodel. toolboxitem ( False )]
// To allow ASP. Net ajax to call this web service from a script, uncomment the downstream service.
// [System. Web. Script. Services. scriptservice]
Public   Class Upfile: system. Web. Services. WebService
{

[Webmethod]
Public   String Uploadfile ( Byte [] FS, String Filename)
{
Try
{
/// Define and instantiate a memory stream to store the submitted byte array.
Memorystream m =   New Memorystream (FS );
/// Define the actual object and save the uploaded object.
Filestream F =   New Filestream (server. mappath ( " . " ) +   " \\ "
+ Filename, filemode. Create );
/// Write Data in the internal memory to a physical file
M. writeto (f );
M. Close ();
F. Close ();
F =   Null ;
M =   Null ;
Return   " The file has been uploaded successfully. " ;
}
Catch (Exception ex)
{
Return Ex. message;
}
}

}
}

 

 

CS ApplicationProgramCall

Code
Private   Void Button#click ( Object Sender, eventargs E)
{
Upfile. upfile UF =   New Windowsformsapplication1.upfile. upfile ();
Fileinfo fi =   New Fileinfo ( @" F: \ \ img_0220.jpg " );
Byte [] B = New   Byte [Fi. Length];
System. Io. filestream FS = Fi. openread ();
FS. Read (B, 0 , Convert. toint32 (Fi. Length ));
For ( Int I =   0 ; I <   10 ; I ++ )
{
Uf. uploadfile (B, " ABC "   + System. guid. newguid () +   " . Jpg " );
}< 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.