zoukankan      html  css  js  c++  java
  • 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控件
  • 相关阅读:
    AT&T不能访问公司网络
    尝鲜:windows 7 来了
    .net控件编程 资料篇
    Annual part 2009
    从Visual studio 2005移出Visual Assist
    不能在IIS 5.1增加应用程序扩展的BUG
    The problem of the user is not associated with a trusted sql server connection 混合登录选项设置的问题
    让我们难忘的那些歌曲
    分享利用VPC防止病毒软件的进入你的windows电脑
    杂读 May 12,2008
  • 原文地址:https://www.cnblogs.com/xvqm00/p/1563412.html
Copyright © 2011-2022 走看看