webservice 上传图片、下载图片


    #region 上传图片
    
/// <summary>
    
/// 上传图片
    
/// </summary>
    [WebMethod(Description = "上传图片", EnableSession = true)]
    
public bool UploadFile(byte[] fs, string FileName,string oldPricute)
    {
        
try
        {
            
///定义并实例化一个内存流,以存放提交上来的字节数组。
            MemoryStream m = new MemoryStream(fs);
            
///定义实际文件对象,保存上载的文件。
            //FileStream f = new FileStream(Server.MapPath(".") + "\\"
            
// + FileName, FileMode.Create);
            String path = Function.GetStringValue(Application[BusParameter.PRO_IMAGE_SAVE_POSITION]);
            
if (!System.IO.Directory.Exists(path))
                System.IO.Directory.CreateDirectory(path);
            FileStream f 
= new FileStream(path + "\\" + FileName, FileMode.Create);
            
///把内内存里的数据写入物理文件
            m.WriteTo(f);
            m.Close();
            f.Close();
            f 
= null;
            m 
= null;
            
//return "文件已经上传成功。";
            if (File.Exists(path + "\\" + "abc" + oldPricute + ".jpg"))
                File.Delete(path 
+ "\\" + "abc" + oldPricute + ".jpg");
            
return true;
        }
        
catch (Exception ex)
        {
            
return false;
            
//this.WriteErrorLog(ex);
            
//throw new SoapException(ex.Message, SoapException.ServerFaultCode);
        }
    }
    
#endregion
//WinForm
WinForm

下载图片代码:
Code
//WinForm

byte
[] proImage = Services.BASService.GetImage(string.Format("abc{0}.jpg",this.Pricture));
picProduct.Image 
= Converter.BytesToBitmap(proImage);//picProduct为pictureBox控件
posted @ 2009-09-09 17:15  大明1986  阅读(6250)  评论(0)    收藏  举报