利用SOAP(Webservice)上传文件

王朝c#·作者佚名  2006-12-17
宽屏版  字体: |||超大  

本文系鼎鼎原创,如转载,请注明出处:http://blog.csdn.net/weisunding

[WebMethod(Description="上传并保存图片文件")]

public bool SaveFile(byte[] binData,string fileName){

bool success=false;

string savePath=System.Configuration.ConfigurationSettings.AppSettings["UploadDirectory"];

if(savePath==null) savePath="Photo";

if(savePath.IndexOf(":\\")<0) savePath=Server.MapPath(savePath);//不是绝对路径

if(!savePath.EndsWith("\\")) savePath += "\\";

if(!Directory.Exists(savePath)){

throw new Exception("服务器端没有找到有效的保存路径!");

}

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;

}

解决思路:编写WebService过程SaveFile(byte[] binData,string fileName0;

客户端直接用调用,把数据流作参数传上来就完了。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有