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();
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。