Network.UploadFile problem in VB.Net 2005

L

lgbjr

Hi All,

I thought this was going to be a simple task, but I just can't get this to
work:

I need to transfer a file from a client machine to a server using a windows
app created with VB.Net 2005. This task led me to
My.Computer.Network.UploadFile.

The user clicks a button, which opens an OpenFileDialog. They select a file
and click ok. the file should then be transferred to the server. This is
what I've tried:

Dim result As DialogResult
result = OpenFileDialog1.ShowDialog
Try
If result = Windows.Forms.DialogResult.OK Then
Dim credentials As Net.NetworkCredential
credentials = New Net.NetworkCredential("test", "test")
Dim StartFile As String =
OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\")
+ 1)
Dim DestFile As Uri = New
Uri("file://v-cnrgi-server/RNPMI_Files/" + StartFile)
My.Computer.Network.UploadFile(OpenFileDialog1.FileName,
DestFile, credentials, True, 100, FileIO.UICancelOption.ThrowException)
End If
Catch ex As System.Net.WebException
Debug.WriteLine(ex.Message + vbCrLf + ex.Status.ToString + vbCrLf +
vbCrLf + ex.StackTrace)
Catch Oex As Exception
Debug.WriteLine(Oex.Message + vbCrLf + Oex.StackTrace)
End Try

On the server, I have a folder called "RNPMI_Files" that is shared and the
user "test" has fullcontrol rights. I've tried this without using the
NetworkCredential (just using the user name and password as string values)
as well. Both results are: "The request was aborted: The request was
canceled."

If I add "Everyone" with fullcontrol to the folder, the file uploads fine.
If I map the shared folder to a drive, and use "different user name" (test
and test), I can mount the folder. So, from my development machine, I can
upload to the folder if the permissions include fullcontrol for everyone,
and I can map the folder to a drive and use the appropriate username and
password and it works.

Any ideas why Network.UploadFile doesn't work with the same user name and
password that works for mapping the folder to a drive?

TIA
Lee
 

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

Top