热门关键字:  PHP  Cisco  seo  网络广告 虚拟主机 中文域名

使用 .NET XML Web Services上传文件

来源:网易虚拟社区 北京站 作者:lumingtong 时间:2005-10-07 点击:
文件上传至asp.net webservice的一种方法

IIS ASP.net webservice服务端

    Public Function uploadfile(filename as String,filecontent() As Byte) As String
      Dim m As New MemoryStream(filecontent)
      Dim f As New FileStream(filename, FileMode.Create)
      m.WriteTo(f)
      m.Close()
      f.Close()      
      Return "OK"
     End Function

winform客户端
把文件内容读到数组里.

    Imports System.IO
    Imports System.Enum
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim f As System.IO.File
      Dim fs As System.IO.FileStream
      Dim uploadservice As New txsvr06.Service1
      Dim localfilename,serverfilename as String
      localfilename="c:\test.txt"
      serverfilename="d:\wwwroot\uploadfiles\test.txt"
      fs = f.Open(localfilename, IO.FileMode.Open, IO.FileAccess.Read)
      Dim filecontent(fs.Length - 1) As Byte
      fs.Read(filecontent, 0, fs.Length)    
      MsgBox(uploadservice.UploadFile(serverfilename,filecontent))
      f = Nothing
      fs.Close()
    End Sub

文件名不必用绝对路径.

如果serverfilename不用绝对路径,则在服务器端
把Dim f As New FileStream(filename, FileMode.Create)
改为Dim f As New FileStream(server.mappath(filename), FileMode.Create)

作者:lumingtong【atong】

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
赞助商连接