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 >}