在WebService 中又不能用Response  所以就不知道怎么办了。?谢谢各位大哥大姐的指点!!!

解决方案 »

  1.   


    /// <summary>
    /// 分块上传文件
    /// </summary>
    /// <param name="bt"></param>
    /// <param name="fileName"></param>
    /// <param name="oldFileName"></param>
    /// <returns></returns>
    [WebMethod(Description="上传附件")] 
    public bool AttachUpLoad1(byte[] bt,string fileName,string oldFileName)
    {
    string attachPath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"]; string filePath=Server.MapPath(attachPath);
    filePath=filePath+"\\";
    string fileName1=fileName.Substring(0,4);
    string fileName2=fileName.Substring(0,8);
    int a=oldFileName.LastIndexOf(".");
    string fileType=oldFileName.Substring(a);
    string strDateFileName=""; FileStream fs=null;
    try
    { if (!Directory.Exists(filePath+fileName1))
    {
    Directory.CreateDirectory(filePath+fileName1);

    }

    if(!Directory.Exists(filePath+fileName1+"\\"+fileName2))
    {
    Directory.CreateDirectory(filePath+fileName1+"\\"+fileName2);
    }

    strDateFileName = filePath+fileName1+"\\"+fileName2+"\\"+fileName+fileType; //文件不存在
    if(!File.Exists(strDateFileName))
    {                   
    fs = new FileStream(strDateFileName,FileMode.Create,FileAccess.Write,FileShare.None);
    }
    else
    {
    fs = new FileStream(strDateFileName,FileMode.Append,FileAccess.Write,FileShare.None);


    fs.Write(bt, 0, bt.Length);
    fs.Close();
    bt=null;
    fs=null;
    return true;
    }
    catch(Exception ex)
    {
    bt=null;
    fs=null;
    return false;
    }
    }
      

  2.   

    把文件转化为 2进制流 
    然后的调用 WebService 的方法 AttachUpLoad1();
    第一个参数是 2进制流的文件 后面的是服务器的文件名和 文件以前的名字
      

  3.   


    #region 下载附件
    /// <summary>
    /// 读取的文件
    /// </summary>
    /// <param name="fileName">日期文件名</param>
    /// <returns>读取的文件字节数组</returns>
    [WebMethod(Description="下载附件")]  
    public byte[] AttachDownLoad(string fileName)
    {
    string filePath=System.Configuration.ConfigurationSettings.AppSettings["AttachPath"];
    filePath=Server.MapPath(filePath)+"\\";
    string fileName1=fileName.Substring(0,4);
    string fileName2=fileName.Substring(0,8);
    try

    FileStream fs=new FileStream(filePath+fileName1+"\\"+fileName2+"\\"+fileName,FileMode.Open);
    long i=fs.Length;
    byte[] b=new byte[i];
    fs.Read(b,0,b.Length);
    fs.Close();
    fs=null;
    return b;
    }
    catch(Exception ex)
    {
    Console.Write(ex.ToString());
    return null;
    }

    }
    #endregion
      

  4.   

    自己写算法 压缩解压,实在不愿意的话 介绍你一个方法:安装完 winrar后 在安装目录下有个 dos 下的压缩解压工具 功能很强大  可以压缩 或者加密等  具体看帮助吧。(文件名就是 Rar.exe)