WebService传输文件的几个知识点

1.通过byte传输

把文件转换

  public static byte[] ConvertToBinary(string Path)
 

       {
            FileStream stream = new FileInfo(Path).OpenRead();
            byte[] buffer = new byte[stream.Length];
            Console.WriteLine("The lenght of the file is "+buffer.Length);
            stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
            return buffer;
        }

static byte[] buffer;

buffer = ConvertToBinary(path);

 

webService

  

FileStream fstream = new FileStream(filePath + fileName, FileMode.Append);
        try
        {
            //MemoryStream m = new MemoryStream(fileBt);
            //m.WriteTo(fstream);
            fstream.Write(fileBt, 0, fileBt.Length);   //二进制转换成文件
          
            fstream.Close();
            //rst += "\r\n";
            rst += "File Name is:" + fstream.Name + "\r\n";
            rst += "File Lenght is:" + fstream.Length + "\r\n";
            rst += "File Position is:" + fstream.Position  + "\r\n";
        }
        catch (Exception ex)
        {
            //抛出异常信息
           rst = ex.ToString();
        }
        finally
        {
           
            fstream.Close();
        }

WebService传输文件的几个知识点,布布扣,bubuko.com

WebService传输文件的几个知识点

上一篇:Linux服务器安装GaussDB 100及安装过程中常见问题解决


下一篇:html5.js 通过扩展js的prototype 让不支持html5的浏览器支持html5函数 (持续新增)