Z
zino
what should I do to be able to make "InputStream.Write" work ?
In the Silverlight "Page.xaml" I have a button wired to the following:
sub button_click()
Dim dlg As New OpenFileDialog
dlg.Filter = "All files|*.*"
If dlg.ShowDialog Then
Dim ub As New UriBuilder("http://localhost:3064/myHandler.ashx")
ub.Query = String.Format("fileName={0}", dlg.File.Name)
Dim wc As WebClient = New WebClient()
AddHandler wc.OpenWriteCompleted, AddressOf myCustomFunction
wc.OpenWriteAsync(ub.Uri, "POST")
end if
end sub
The webClient that receive the request is:
Public Class myHandler
Implements System.Web.IHttpAsyncHandler
Public Function BeginProcessRequest(ByVal context As System.Web.HttpContext,
ByVal cb As System.AsyncCallback, ByVal extraData As Object) As
System.IAsyncResult Implements
System.Web.IHttpAsyncHandler.BeginProcessRequest
Dim fileName As String = context.Request.QueryString("filename")
Using fs As New
System.IO.FileStream(context.Server.MapPath("~/Files/" &
fileName), IO.FileMode.Create,
IO.FileAccess.ReadWrite)
Using stream As System.IO.Stream = context.Request.InputStream
If stream.CanWrite Then '''''' THIS always return False
Dim size As Integer = CInt(stream.Length)
Dim bytes(size) As Byte
Dim numBytes As Integer
numBytes = stream.Read(bytes, 0, size)
'''''' if I skip the "IF" statement, this line generate
"Specified method is not supported" error
stream.Write(bytes, 0, numBytes)
stream.Close()
stream.Dispose()
End If
End Using
end Using
end function
end class
What am I doing wrong ?
thanks for help
In the Silverlight "Page.xaml" I have a button wired to the following:
sub button_click()
Dim dlg As New OpenFileDialog
dlg.Filter = "All files|*.*"
If dlg.ShowDialog Then
Dim ub As New UriBuilder("http://localhost:3064/myHandler.ashx")
ub.Query = String.Format("fileName={0}", dlg.File.Name)
Dim wc As WebClient = New WebClient()
AddHandler wc.OpenWriteCompleted, AddressOf myCustomFunction
wc.OpenWriteAsync(ub.Uri, "POST")
end if
end sub
The webClient that receive the request is:
Public Class myHandler
Implements System.Web.IHttpAsyncHandler
Public Function BeginProcessRequest(ByVal context As System.Web.HttpContext,
ByVal cb As System.AsyncCallback, ByVal extraData As Object) As
System.IAsyncResult Implements
System.Web.IHttpAsyncHandler.BeginProcessRequest
Dim fileName As String = context.Request.QueryString("filename")
Using fs As New
System.IO.FileStream(context.Server.MapPath("~/Files/" &
fileName), IO.FileMode.Create,
IO.FileAccess.ReadWrite)
Using stream As System.IO.Stream = context.Request.InputStream
If stream.CanWrite Then '''''' THIS always return False
Dim size As Integer = CInt(stream.Length)
Dim bytes(size) As Byte
Dim numBytes As Integer
numBytes = stream.Read(bytes, 0, size)
'''''' if I skip the "IF" statement, this line generate
"Specified method is not supported" error
stream.Write(bytes, 0, numBytes)
stream.Close()
stream.Dispose()
End If
End Using
end Using
end function
end class
What am I doing wrong ?
thanks for help