This article is an example of the ASP.net based on Web service to achieve remote upload pictures. Share to everyone for your reference, specific as follows:
Page call Code: Prerequisite Add Web Reference
httpfilecollection files = HttpContext.Current.Request.Files;
String filePath = Files[0]. FileName;
String fileName = Filepath.substring (Filepath.lastindexof ("//") + 1);
byte[] datas = new Byte[files[0]. ContentLength];
System.IO.Stream FS;
localhost. WebService web = new localhost. WebService ();
FS = (System.IO.Stream) files[0]. InputStream;
Reads the input stream into a two-dimensional array of
FS. Read (datas, 0, Files[0]. ContentLength);
Fs. Close ();
Response.Write (web. UploadFile (Datas,filename));
Code in WEB Service
[WebMethod (description= "Upload server picture information, return success")]
public string UploadFile (byte[] fs,string fileName)
{
//create a memory stream to write an array to the memory stream
MemoryStream memory = new MemoryStream (FS);
Write the contents of the memory into the file stream
= FileStream stream = new FileStream (HttpContext.Current.Server.MapPath (".") + "//images" + fileName, FileMode.Create);
Writes the contents of the memory stream into the FileStream stream
memory. WriteTo (stream);
Stream. Close ();
memory = NULL;
stream = null;
Return "File Upload success!";
}
I hope this article will help you to ASP.net program design.