Upload a file using SOAP (Webservice)

Source: Internet
Author: User
Tags soap
This series Ding original, such as Reprint, please indicate the source: http://blog.111cn.net/weisunding
[WebMethod (Description = "upload and save image files")]
Public bool SaveFile (byte [] binData, string fileName ){
Bool success = false;
String savePath = System. Configuration. ConfigurationSettings. Receivettings ["UploadDirectory"];
If (savePath = null) savePath = "Photo ";
If (savePath. IndexOf (":") <0) savePath = Server. MapPath (savePath); // not an absolute path
If (! SavePath. EndsWith ("") savePath + = "";
If (! Directory. Exists (savePath )){
Throw new Exception ("no valid storage path found on the server side! ");
}

FileStream fileStream = null;
Try {
FileStream = new FileStream (savePath + fileName, FileMode. Create, FileAccess. Write );
// Write the file
FileStream. Write (binData, 0, binData. Length );
FileStream. Flush (); // clear the buffer, write the data to the hard disk
Success = true;
} Catch (Exception ex ){
Throw new Exception (ex. Message );
} Finally {
FileStream. Close ();
}
Return success;

}
Solution: compile the SaveFile (byte [] binData, string fileName0;
The client directly calls the data stream as a parameter.


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.