How can I save to a file to the PDA?

  • Thread starter Thread starter Me
  • Start date Start date
M

Me

I downloaded a JPG stream from a URI using a WebRequest

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream

I then convert the response to a bitmap file
PictureBox1.Image = New Bitmap(ResponseStream)

What I would like to do now is to to save the file to the PDA?

Is there any straightforward, easy way to do this in CF?

Thanks,

Gigi
 
I suggest you save the ResposeStream content in a byte[]
and
1. create a bitmap from these byte[](s)
2. save this byte[](s) in a file
 
Thanks Lloyd.

Can you recommend where I can get any such code samples in vb.net?


Thanks,

Gigi

Lloyd Dupont said:
I suggest you save the ResposeStream content in a byte[]
and
1. create a bitmap from these byte[](s)
2. save this byte[](s) in a file

Me said:
I downloaded a JPG stream from a URI using a WebRequest

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream

I then convert the response to a bitmap file
PictureBox1.Image = New Bitmap(ResponseStream)

What I would like to do now is to to save the file to the PDA?

Is there any straightforward, easy way to do this in CF?

Thanks,

Gigi
 
not in VB.NET
but just out of mind here is how I will do in (C# looking) pseudo code

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream
byte[] buf = new byte[Response.ContentLength];
int nread, pos=0, len = buf.Length;
while(len > 0)
{
nread = ResponseStream.Read(buf, pos, len);
if(nread > 0)
{
pos += nread;
len -= nread;
}
}

Bitmap b = new Bitmap(new MemoryStream(buf));
FileStream fs = new FileStream("myfile.jpg");
fs.Write(buf, 0, buf.Length);
fs.Close();

Me said:
Thanks Lloyd.

Can you recommend where I can get any such code samples in vb.net?


Thanks,

Gigi

Lloyd Dupont said:
I suggest you save the ResposeStream content in a byte[]
and
1. create a bitmap from these byte[](s)
2. save this byte[](s) in a file

Me said:
I downloaded a JPG stream from a URI using a WebRequest

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream

I then convert the response to a bitmap file
PictureBox1.Image = New Bitmap(ResponseStream)

What I would like to do now is to to save the file to the PDA?

Is there any straightforward, easy way to do this in CF?

Thanks,

Gigi
 
Lloyd,

Thanks for your response. I looked at your code and the code in the Stream
Class. I actually tried both, but the problem that I am now having is that
the stream that :

? ResponseStream
{System.Net.ConnectStream}
[System.Net.ConnectStream]: {System.Net.ConnectStream}
CanRead: True
CanSeek: False
CanWrite: False
Length: <error: an exception of type: {System.NotSupportedException}
occurred>
Null: {System.IO.Stream.NullStream}
Position: <error: an exception of type: {System.NotSupportedException}
occurred>.

I can load the stream into the bitmap and display it, but I can only
intermittantly load it into the Read method and put it in the byte buffer.

Any suggestions?

Thanks,

Gigi

Lloyd Dupont said:
not in VB.NET
but just out of mind here is how I will do in (C# looking) pseudo code

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream
byte[] buf = new byte[Response.ContentLength];
int nread, pos=0, len = buf.Length;
while(len > 0)
{
nread = ResponseStream.Read(buf, pos, len);
if(nread > 0)
{
pos += nread;
len -= nread;
}
}

Bitmap b = new Bitmap(new MemoryStream(buf));
FileStream fs = new FileStream("myfile.jpg");
fs.Write(buf, 0, buf.Length);
fs.Close();

Me said:
Thanks Lloyd.

Can you recommend where I can get any such code samples in vb.net?


Thanks,

Gigi

Lloyd Dupont said:
I suggest you save the ResposeStream content in a byte[]
and
1. create a bitmap from these byte[](s)
2. save this byte[](s) in a file

I downloaded a JPG stream from a URI using a WebRequest

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream

I then convert the response to a bitmap file
PictureBox1.Image = New Bitmap(ResponseStream)

What I would like to do now is to to save the file to the PDA?

Is there any straightforward, easy way to do this in CF?

Thanks,

Gigi
 
In spite of the messages that I received, I was finally able to get the
stream loaded into the bitmap file and saved to disk. By reading the stream
into a PictureBox.Image FIRST, I was unable to read it again into another
stream because the original jpeg file was readable only, and not seekable.
Thus, I could not place the pointer from the end of file to the beginning of
file.

Simply reading the jpeg into a stream and loading it into the file first,
then using the contents of the file to display to the PictureBox works fine
ALMOST.

I works like a charm on the Desktop.

I'm getting an error when I try to load the file on the PDA although a file
is indeed stored. I'm still working through this issue.

I will let you all know how I do.

Thanks,

Gigi

Me said:
Lloyd,

Thanks for your response. I looked at your code and the code in the Stream
Class. I actually tried both, but the problem that I am now having is that
the stream that :

? ResponseStream
{System.Net.ConnectStream}
[System.Net.ConnectStream]: {System.Net.ConnectStream}
CanRead: True
CanSeek: False
CanWrite: False
Length: <error: an exception of type: {System.NotSupportedException}
occurred>
Null: {System.IO.Stream.NullStream}
Position: <error: an exception of type: {System.NotSupportedException}
occurred>.

I can load the stream into the bitmap and display it, but I can only
intermittantly load it into the Read method and put it in the byte buffer.

Any suggestions?

Thanks,

Gigi

Lloyd Dupont said:
not in VB.NET
but just out of mind here is how I will do in (C# looking) pseudo code

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream
byte[] buf = new byte[Response.ContentLength];
int nread, pos=0, len = buf.Length;
while(len > 0)
{
nread = ResponseStream.Read(buf, pos, len);
if(nread > 0)
{
pos += nread;
len -= nread;
}
}

Bitmap b = new Bitmap(new MemoryStream(buf));
FileStream fs = new FileStream("myfile.jpg");
fs.Write(buf, 0, buf.Length);
fs.Close();

Me said:
Thanks Lloyd.

Can you recommend where I can get any such code samples in vb.net?


Thanks,

Gigi

I suggest you save the ResposeStream content in a byte[]
and
1. create a bitmap from these byte[](s)
2. save this byte[](s) in a file

I downloaded a JPG stream from a URI using a WebRequest

Request = WebRequest.Create(http://myWebpage.jpg)
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream

I then convert the response to a bitmap file
PictureBox1.Image = New Bitmap(ResponseStream)

What I would like to do now is to to save the file to the PDA?

Is there any straightforward, easy way to do this in CF?

Thanks,

Gigi
 
I thank you for your responses! After some careful inspection of my code, I
finally sorted out the problem. Here is the working code:

Dim Response As WebResponse
Dim ResponseStream As Stream
Dim Request As WebRequest


Request = WebRequest.Create("http://www.images.image.jpg")
Response = Request.GetResponse
ResponseStream = Response.GetResponseStream


Dim numBytesToRead As Integer = CInt(Response.ContentLength)

Dim bytes(Response.ContentLength) As Byte
Dim numBytesRead As Integer = 0
While numBytesToRead + 1 > 0
Dim n As Integer = ResponseStream.Read(bytes, numBytesRead,
numBytesToRead)
' The end of the file has been reached.
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While

'Cursor.Current = Cursors.Default
'Response.Close()


Dim b As Bitmap
b = New Bitmap(New MemoryStream(bytes))

Dim fs As New FileStream("myfileB.jpeg", FileMode.Create)

fs.Write(bytes, 0, bytes.Length)

fs.Close()

Cursor.Current = Cursors.Default
Response.Close()

Dim myBitmap As Bitmap
myBitmap = New Bitmap("myfileB.jpeg")

PictureBox1.Image = myBitmap
PictureBox1.Update()

Gigi
 
Back
Top