c# webservice 下载
时间: 2023-10-07 19:11:57 浏览: 81
在C# WebService中,可以使用以下代码实现文件下载功能:
```csharp
namespace web {
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService {
[WebMethod(Description = "下载服务器站点文件,传递文件相对路径")]
public byte[] DownloadFile(string strFilePath) {
FileStream fs = null;
string CurrentUploadFolderPath = Server.MapPath(ConfigurationManager.AppSettings["UploadFileFolder"]);
string CurrentUploadFilePath = CurrentUploadFolderPath + strFilePath;
if (File.Exists(CurrentUploadFilePath)) {
try {
fs = File.OpenRead(CurrentUploadFilePath);
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
阅读全文