This series ding original, such as reprint, please indicate the source: http://blog.csdn.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.