服务器端:
[WebMethod]
public byte[] DownloadFile(string file)
{
System.IO.FileStream fs = null;
if (System.IO.File.Exists(file))
{
try
{
fs = System.IO.File.OpenRead(file);
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while ((b1 = fs.ReadByte()) != -1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}
catch (Exception ex)
{
return new byte[0];
}
finally
{
fs.Close();
}
}
else
{
return new byte[0];
}
}
客户端:
/// <summary>
/// 从服务器上下载文件,未用
/// </summary>
/// <param name="str1">源文件:如“E:\\city.txt”</param>
/// <param name="str2">目标文件:如@"d:\city.txt"</param>
public static void DownFile(string str1, string str2)
{
CRMweb.WebService1SoapClient myWeb = new CRMweb.WebService1SoapClient();
byte[] bs = myWeb.DownloadFile(str1);
System.IO.FileStream stream = new System.IO.FileStream(str2, System.IO.FileMode.CreateNew);
stream.Write(bs, 0, bs.Length);
stream.Flush();
stream.Close();
}