inputStream.canWrite always return FALSE

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
 
H

Hans Kesting

zino was thinking very hard :
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

That is expected behaviour (at least *I* expect it :) ).
The POST from the silverlight client (running in the browser) sends the
whole contents of that file to the server. Only then the server-side
processing can start. It is not possible to change the original file,
if that's what you are trying to do.

What are you trying to do?

Hans Kesting
 
Z

zino

I'm imbedding the silverlight control in a aspx page.
I need to let user select a file on his end, then, the silverlight control
need to upload this file to the server, save it, and if everything is
successfull, let user know.

I'm trying to follow Tim Heuer video on Silverlight web site, and I'm not
sure about what I'm doing myself, since that's my first silverlight code
ever, and I'm trying to understand how things work here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top