473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Expert help needed

Hello,

We have some code (see below) that has been working intermittently
and I was wondering if someone had a better approach or an idea on why we
get these errors. This part of code basically gets a file and uploads it
from a cable or DSL connection to our t1 line to a server. The file size
ranges from 1.7 MB to 4MB and there can be between 1-40 files that need to
be uploaded to our server. We also could have multiple laptops running this
application at the same time from different locations. The folder the file
is trying to be stored to has everyone with full permissions. Any help would
be greatly appreciated.
Front end vb app code:
Private Function UploadPhotos(ByVal filename As String) As Boolean

Try

Dim f As System.IO.File

Dim fs As System.IO.FileStream

Dim Service As New host.Service
Dim credentials As System.Net.NetworkCredential = New
System.Net.NetworkCredential("username", "password")

Service.Credentials = credentials

Service.Url = ServiceUrl

Service.Timeout = 1800000

Dim TstUpload As String

fs = f.Open(UploadDirectory & filename, IO.FileMode.Open,
IO.FileAccess.Read)

Dim b(CInt(fs.Length) - 1) As Byte

fs.Read(b, 0, CInt(fs.Length))

Try

TstUpload = Service.UploadFile(b, filename).ToString

Catch ex As Exception

Msgbox(ex.StackTrace.ToString)

Return False

End Try

f = Nothing

fs.Close()

Service.Dispose()

Return True

Catch ex As Exception

Msgbox(ex.StackTrace.ToString)

Return False

End Try

End Function
Backend Webservice code:
<WebMethod()> Public Function UploadFile(ByVal fs() As Byte, ByVal FlName As
String) As Boolean

Try

Dim m As New System.IO.MemoryStream(fs)

Dim f As New System.IO.FileStream("e:\folder1\folder2\" & FlName,
IO.FileMode.Create)

m.WriteTo(f)

m.Close()

f.Close()

f = Nothing

m = Nothing

Return True

Catch ex As Exception

Return False

End Try

End Function
Some errors:
failed to upload file:db9431.zip the underlying connection was closed: an
unexpected error occurred on a receive. Trace: at
System.Web.Services.Protocols.WebClientProtocol.Ge tWebResponse(WebRequest
request)

at
System.Web.Services.Protocols.HttpWebClientProtoco l.GetWebResponse(WebReques
t request)

at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)

at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)

at sync.Form1.UploadPhotos(String filename)

failed to upload file:db9231.zip the request failed with http status 401:
access denied. Trace: at
System.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)

at sync.localhost.Service.UploadFile(Byte[] fs, String FlName)

at sync.Form1.UploadPhotos(String filename)

Nov 20 '05 #1
15 1665
Cor
Hi Jake,

I have changed a sample I had by using a webservice, have a look to it.

In this test I use a XML dataset

I hope this helps?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function

<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
Nov 20 '05 #2
Cor
Hi Jake,

I have changed a sample I had by using a webservice, have a look to it.

In this test I use a XML dataset

I hope this helps?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function

<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////
Nov 20 '05 #3
Hi Cor,

Thanks for the sample. However this sticks the file in a database while
we are actually transferring the physical files themselves. Looking at my
code can you see any issues with why we are getting those errors? Any help
would be greatly appreciated.

Jake

"Cor" <no*@non.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
Hi Jake,

I have changed a sample I had by using a webservice, have a look to it.

In this test I use a XML dataset

I hope this helps?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function

<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////

Nov 20 '05 #4
Hi Cor,

Thanks for the sample. However this sticks the file in a database while
we are actually transferring the physical files themselves. Looking at my
code can you see any issues with why we are getting those errors? Any help
would be greatly appreciated.

Jake

"Cor" <no*@non.com> wrote in message
news:Os**************@TK2MSFTNGP11.phx.gbl...
Hi Jake,

I have changed a sample I had by using a webservice, have a look to it.

In this test I use a XML dataset

I hope this helps?

Cor

\\\needs a picturebox and 4 buttons on a windowform
Dim ds As New DataSet
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice dataset
Dim ws As New localhost.DataBaseUpdate
ws.SetDataset(abyt)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice dataset
Dim ws As New localhost.DataBaseUpdate
abyt = ws.GetByte
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
End Class
////
\\\\Webservice
<WebMethod()> _
Public Function GetByte() As Byte()
Dim ds As New DataSet
ds.ReadXml("C:\wsblob.xml")
Return CType(ds.Tables(0).Rows(0)(0), Byte())
End Function

<WebMethod()> _
Public Sub SetDataset(ByVal abyte As Byte())
Dim ds As New DataSet
ds.Tables.Add(New DataTable("Photo"))
ds.Tables(0).Columns.Add(New DataColumn("Sample"))
ds.Tables(0).Columns(0).DataType = GetType(System.Byte())
ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
ds.Tables(0).Rows(0)(0) = abyte
ds.WriteXml("C:\wsblob.xml", XmlWriteMode.WriteSchema)
End Sub
////

Nov 20 '05 #5
Cor
Hi Jake,

Thanks for the sample. However this sticks the file in a database while we are actually transferring the physical files themselves. Looking at my
code can you see any issues with why we are getting those errors? Any help
would be greatly appreciated.


That dataset was something extra, here I changed it that it does images
direct.

Give it a try?

Cor

\\\
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice file
Dim ws As New localhost.PhotoUpdate
ws.SetFile("C:\myjpg.jpg", abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice file
Dim ws As New localhost.PhotoUpdate
abyt = ws.GetFile("c:\myjpg.jpg")
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///
\\\webservice
<WebMethod()> _
Public Function GetFile(ByVal myjpg As String) As Byte()
Dim abyt() As Byte
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
Return abyt
End Function
<WebMethod()> _
Public Sub SetFile(ByVal myjpg As String, ByVal abyt As Byte())
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End Sub
////
Nov 20 '05 #6
Cor
Hi Jake,

Thanks for the sample. However this sticks the file in a database while we are actually transferring the physical files themselves. Looking at my
code can you see any issues with why we are getting those errors? Any help
would be greatly appreciated.


That dataset was something extra, here I changed it that it does images
direct.

Give it a try?

Cor

\\\
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice file
Dim ws As New localhost.PhotoUpdate
ws.SetFile("C:\myjpg.jpg", abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice file
Dim ws As New localhost.PhotoUpdate
abyt = ws.GetFile("c:\myjpg.jpg")
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///
\\\webservice
<WebMethod()> _
Public Function GetFile(ByVal myjpg As String) As Byte()
Dim abyt() As Byte
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
Return abyt
End Function
<WebMethod()> _
Public Sub SetFile(ByVal myjpg As String, ByVal abyt As Byte())
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End Sub
////
Nov 20 '05 #7
Cor,

Thanks for the code sample. Can you explain what the major difference
would be between my webserivce and yours? It seems that yours is opening the
file and passing it that way, while mine is converts the file to a byte and
then passes it as well. Any ideas on why we get this error(see below)
//application
Private Function UploadPhotos(ByVal filename As String) As Boolean

Try

Dim f As System.IO.File

Dim fs As System.IO.FileStream

Dim Service As New localhost.VCRService273

Dim credentials As System.Net.NetworkCredential = New
System.Net.NetworkCredential("USER", "Password")

Service.Credentials = credentials

Service.Url = ServiceUrl

Service.Timeout = 3600000

Dim TstUpload As String

fs = f.Open(UploadDirectory & filename, IO.FileMode.Open,
IO.FileAccess.Read)

Dim b(CInt(fs.Length) - 1) As Byte

fs.Read(b, 0, CInt(fs.Length))

Try

TstUpload = Service.UploadFile(b, filename).ToString

Catch ex As Exception

Return False

End Try

f = Nothing

fs.Close()

Service.Dispose()

Return True

Catch ex As Exception

Return False

End Try

end sub

//
<WebMethod()> Public Function UploadFile(ByVal fs() As Byte, ByVal
FlName As String) As Boolean

Try
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream("e:\website\vcnservice\" &
FlName, IO.FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return True

Catch ex As Exception
Return False
End Try

common error:
Failed to upload file:db9913.zip the request failed with http status 401:
access denied. Trace: at
system.Web.Services.Protocols.SoapHttpClientProtoc ol.ReadResponse(SoapClient
Message message, WebResponse response, Stream responseStream, Boolean
asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String
methodName, Object[] parameters)

at application.localhost.Service.UploadFile(Byte[] fs, String FlName)

at application.Form1.UploadPhotos(String filename)

//Your sample
//application
//webservice
<WebMethod()> _
Public Function GetFile(ByVal myjpg As String) As Byte()
Dim abyt() As Byte
Dim fs As New IO.FileStream(myjpg _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
Return abyt
End Function

"Cor" <no*@non.com> wrote in message
news:eo****************@TK2MSFTNGP11.phx.gbl...
Hi Jake,

Thanks for the sample. However this sticks the file in a database

while
we are actually transferring the physical files themselves. Looking at my code can you see any issues with why we are getting those errors? Any help would be greatly appreciated.


That dataset was something extra, here I changed it that it does images
direct.

Give it a try?

Cor

\\\
Private abyt() As Byte
Private fo As New OpenFileDialog
Private sf As New SaveFileDialog
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'Reading a picture from disk and put it in a bytearray
If fo.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(fo.FileName, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
'just to show the sample without a fileread error
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button2.Click
'writing a picture from a bytearray to disk
If sf.ShowDialog = DialogResult.OK Then
Dim fs As New IO.FileStream(sf.FileName, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles Button3.Click
'writing a bytearray to a webservice file
Dim ws As New localhost.PhotoUpdate
ws.SetFile("C:\myjpg.jpg", abyt)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'reading a picture from a webservice file
Dim ws As New localhost.PhotoUpdate
abyt = ws.GetFile("c:\myjpg.jpg")
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)
End Sub
///
\\\webservice
<WebMethod()> _
Public Function GetFile(ByVal myjpg As String) As Byte()
Dim abyt() As Byte
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.Open)
Dim br As New IO.BinaryReader(fs)
abyt = br.ReadBytes(CInt(fs.Length))
br.Close()
Return abyt
End Function
<WebMethod()> _
Public Sub SetFile(ByVal myjpg As String, ByVal abyt As Byte())
Dim fs As New IO.FileStream(myjpg, _
IO.FileMode.CreateNew)
Dim bw As New IO.BinaryWriter(fs)
bw.Write(abyt)
bw.Close()
End Sub
////

Nov 20 '05 #8
Hi Jake,

That 401 is in my opinion a logon code, can you before I check your code
first make with all the things in it to logon a simple "Hello World"
application to see if all the connections and credentials are right, than I
will try to simulate your code tomorrow OK?

Cor
Nov 20 '05 #9
Cor,

Thanks Cor I appreciate it. Some info on the overall app. The function
prior to this one reads a directory of files (all jpgs) and then grabs 2 MB
worth and then moves them to an uptemp folder. Once this process is done
there is between 2 and 30 zip files. The app then reads the uptemp directory
and calls the uploadPhoto service to transfer the files to our server. The
login and password are valid. We have about 50 people using the app. I can
goto a browser and get to the url putting in the login and password. A
simple hello world does work. As for the code I got it pretty much from the
following url http://www.dotnetextreme.com/code/binaryupload.asp So I am
confused on why some people get it(all running the same version of the app
with the same code and all are on W2k mobile tablets). It's not specific to
any person and I do not see a pattern forming, it seems to be a random
thing.

John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ui**************@TK2MSFTNGP11.phx.gbl...
Hi Jake,

That 401 is in my opinion a logon code, can you before I check your code
first make with all the things in it to logon a simple "Hello World"
application to see if all the connections and credentials are right, than I will try to simulate your code tomorrow OK?

Cor

Nov 20 '05 #10
Hi Jake,

I tested it, on a local situation and only in the debugger. To show you
that, I changed the code for it, however that does not affect the original
code from you in my idea, a nice routine to copy zipfiles.

I changed little things afterwards by instance that bool which you did call
as a string and more little things, however I did test that before without
that and was not that important in my idea.

Sorry that I could not find a solution for your problem.

Cor

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.ShowDialog()
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim Service As New localhost.Service1
fs = f.Open(Me.OpenFileDialog1.FileName, IO.FileMode.Open, _
IO.FileAccess.Read)
Dim b(CInt(fs.Length) - 1) As Byte
fs.Read(b, 0, CInt(fs.Length))
Try
If Not Service.UploadFile(b, IO.Path.GetFileName _
(Me.OpenFileDialog1.FileName)) Then
MessageBox.Show("There was an error")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
///
\\\
<WebMethod()> _
Public Function UploadFile(ByVal fs() As Byte, _
ByVal FlName As String) As Boolean
Try
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream("c:\test1\" _
& FlName, IO.FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
///




Nov 20 '05 #11
Cor,

Thanks for the help. I am stumped on this issue as well. The server
doesn't seemed to be taxed in anyway so I am confused on why we would get an
access denied errors, and randomly at that! Can you think of another way to
transfer files programatically from a remote mobile tablet down to our
server? The client connection is DSL or better and we have a T1 on the
server end.

John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uN**************@TK2MSFTNGP09.phx.gbl...
Hi Jake,

I tested it, on a local situation and only in the debugger. To show you
that, I changed the code for it, however that does not affect the original
code from you in my idea, a nice routine to copy zipfiles.

I changed little things afterwards by instance that bool which you did call as a string and more little things, however I did test that before without
that and was not that important in my idea.

Sorry that I could not find a solution for your problem.

Cor

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.ShowDialog()
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim Service As New localhost.Service1
fs = f.Open(Me.OpenFileDialog1.FileName, IO.FileMode.Open, _
IO.FileAccess.Read)
Dim b(CInt(fs.Length) - 1) As Byte
fs.Read(b, 0, CInt(fs.Length))
Try
If Not Service.UploadFile(b, IO.Path.GetFileName _
(Me.OpenFileDialog1.FileName)) Then
MessageBox.Show("There was an error")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
///
\\\
<WebMethod()> _
Public Function UploadFile(ByVal fs() As Byte, _
ByVal FlName As String) As Boolean
Try
Dim m As New System.IO.MemoryStream(fs)
Dim f As New System.IO.FileStream("c:\test1\" _
& FlName, IO.FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
///



Nov 20 '05 #12
Hi Jake,

Are you sure the ASPUSER has the right to write on your server in the
directory you are using.
I would go for tat part first.
Cor
Nov 20 '05 #13
Cor,

Yes the ASPUSER has rights. We get about 95% of the files each day
without any problems. The other 5% seem to get this message. All are using
the same app. In fact sometimes one mobile will upload (out of 10 files)
1-8, error on 9 and then upload 10 so it's not really a permissions issue.

John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:em*************@TK2MSFTNGP11.phx.gbl...
Hi Jake,

Are you sure the ASPUSER has the right to write on your server in the
directory you are using.
I would go for tat part first.
Cor

Nov 20 '05 #14
Hi Jake,

Did you put this question in the newsgroup
microsoft.public.dotnet.framework.compactframework .

You can also crosspost it and then to the newsgroups
framework.public.dotnet.adonet and framework.public.framework.aspnet

I know that Bill Ryan and Eric(EMW) are busy with this.
(Bill is mostly in adonet and Eric I have seen now in aspnet).

Subject:
Problems uploading files from mobile to server

I think they can maybe help you.

Cor
Nov 20 '05 #15
Cor,

Ok I'll post it there. It's not really a mobile device though. It a
tablet pc that runs w2k on it so the code works on both the mobile tablet as
well as desktops.

John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Ow****************@TK2MSFTNGP10.phx.gbl...
Hi Jake,

Did you put this question in the newsgroup
microsoft.public.dotnet.framework.compactframework .

You can also crosspost it and then to the newsgroups
framework.public.dotnet.adonet and framework.public.framework.aspnet

I know that Bill Ryan and Eric(EMW) are busy with this.
(Bill is mostly in adonet and Eric I have seen now in aspnet).

Subject:
Problems uploading files from mobile to server

I think they can maybe help you.

Cor

Nov 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ray | last post by:
Hello, This one I think should be easy when you now how but I couldn't get it today. I have to run a kind of double check routine. 1 database, 2 tables. No linking or referential integrity or...
0
by: Tom Gugger | last post by:
OMNI GROUP tgugger@buckeye-express.com 419-380-8853 BEA MIDDLEWARE EXPERT/ CONTRACT TO PERM/ PA
7
by: John Smith | last post by:
Hi All, Sorry if I am calling expert's advice on such a simple thing. I am reading a c++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS -...
1
by: ViperDK \(Daniel K.\) | last post by:
i've a database where relations are hold in a special way which the project leaders think of as "performant and uncomplicated" but which is very questionable to me:...
1
by: Holli Graham | last post by:
Hi, Could some Opera CSS expert take a look at http://www.cahabagba.com and tell me if there is a problem with my stylesheets or if it's just Opera weirdness? I've tested this on many browsers...
4
by: Tony Houghton | last post by:
Can anyone recommend a good book for intermediate up to expert level? I'm an experienced C programmer and I learnt Python from the "Learning Python" O'Reilly book because it had good reviews. I was...
3
by: Wendell III | last post by:
Meetroduction (Meetro) is looking for a full-time JavaScript expert. Chicago-based startup seeks an experienced, dedicated and energetic JavaScript programmer to develop components of a robust,...
10
by: E.T. Grey | last post by:
Hi, I have a C++ DLL that I want to use from a C# project. I am actually usng a lot of advanced C++ features like templates, partial/specialized templates, functors and callbacks. I am also...
4
by: jesper_lofgren | last post by:
Hi there, I have some webcontrols that i want to add dynamically on a page. I have stored the path / namespace in database (ex MyNameSpace.WebControls.Control1) to the class/webcontrol. Lets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.