473,327 Members | 2,074 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,327 software developers and data experts.

Short VB.NET Project for Filedialog and FTP upload

Dear Newsgroup,

My name is Kai from Germany and I`m trying to learn VB.Net. My first
Project is a simple Form with a button, witch is starting the
filedialog for multiselect file. All thats fine. Now I want
automaticly upload this selected file via FTP.

I'm using Windows.Forms:

My Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDialog.Click

Dim myStream As Stream = Nothing
Dim ofd As New OpenFileDialog()

With ofd
.InitialDirectory = "C:\" 'Preselection Filelocation
.Title = "Selected Files" 'Title
.Filter = "MP3-Format (*.mp3)|*.mp3|WAVE-Format (*.wav)|
*.wav" 'Filefilter
.FilterIndex = 2 'Preselectet Extension
.RestoreDirectory = False
.Multiselect = True 'to select multiple files
End With

If ofd.ShowDialog() = System.Windows.Forms.DialogResult.OK
Then
Try
myStream = ofd.OpenFile()
If (myStream IsNot Nothing) Then
'Here I need to place the Code for Uploading the selected files to a
webserver via ftp
Else
MsgBox("Nothing selected!", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly)
Exit Sub
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original
error: " & Ex.Message)
Finally
' Check this again, since we need to make sure we
didn't throw an exception on open.
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
Oct 19 '08 #1
3 5439
"Kai Apel" <ma**@kaiapel.deschrieb
Dear Newsgroup,

My name is Kai from Germany
There is also
microsoft.public.de.german.entwickler.dotnet.vb
and I`m trying to learn VB.Net. My first
Project is a simple Form with a button, witch is starting the
filedialog for multiselect file. All thats fine. Now I want
automaticly upload this selected file via FTP.
http://msdn.microsoft.com/en-us/library/ms229718.aspx
(sub topic "upload...")

Armin
Oct 19 '08 #2
On Oct 19, 6:51*pm, Kai Apel <m...@kaiapel.dewrote:
Dear Newsgroup,

My name is Kai from Germany and I`m trying to learn VB.Net. My first
Project is a simple Form with a button, witch is starting the
filedialog for multiselect file. All thats fine. Now I want
automaticly upload this selected file via FTP.

I'm using Windows.Forms:

My Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDialog.Click

* * * * Dim myStream As Stream = Nothing
* * * * Dim ofd As New OpenFileDialog()

With ofd
* * * * * * .InitialDirectory = "C:\" 'Preselection Filelocation
* * * * * * .Title = "Selected Files" 'Title
* * * * * * .Filter = "MP3-Format (*.mp3)|*.mp3|WAVE-Format(*.wav)|
*.wav" 'Filefilter
* * * * * * .FilterIndex = 2 'Preselectet Extension
* * * * * * .RestoreDirectory = False
* * * * * * .Multiselect = True 'to select multiple files
End With

* * * * If ofd.ShowDialog() = System.Windows.Forms.DialogResult..OK
Then
* * * * * * Try
* * * * * * * * myStream = ofd.OpenFile()
* * * * * * * * If (myStream IsNot Nothing) Then

'Here I need to place the Code for Uploading the selected files to a
webserver via ftp

* * * * * * * * Else
* * * * * * * * * * MsgBox("Nothing selected!", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly)
* * * * * * * * * * Exit Sub
* * * * * * * * End If
* * * * * * Catch Ex As Exception
* * * * * * * * MessageBox.Show("Cannot read file from disk. Original
error: " & Ex.Message)
* * * * * * Finally
* * * * * * * * ' Check this again, since we need to makesure we
didn't throw an exception on open.
* * * * * * * * If (myStream IsNot Nothing) Then
* * * * * * * * * * myStream.Close()
* * * * * * * * End If
* * * * * * End Try
* * * * End If
Hi,
To try to upload multiple selected files to your FTP server you can
try this:

First retrieve multi-selected filenames in a for-each loop then upload
each file using My.Computer.Network.UploadFile method:

'--------------------------------------
'.......The rest is above in your code
For Each file As String In ofd.FileNames

'Return filenames with extension
Dim filename As String
filename = System.IO.Path.GetFileName(file)

' Do the uploading
My.Computer.Network.UploadFile(file, _
"ftp://domain.com/folder/" & filename, _
"user", "pass")

Next
'--------------------------------------

A few notes, uploading multiple files at once may (and probably will)
block your UI (form) and you may need to go with multi-threaded
approach like using BackgroundWorker. Also, you can think other usage
of UploadFile method, so see the overload list here:

http://msdn.microsoft.com/en-us/libr...le(VS.80).aspx
Hope this helps,

Onur Güzel
Oct 19 '08 #3
thx for the answer.

K
Oct 19 '08 #4

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

Similar topics

4
by: ulysses | last post by:
Hi, I use PyQt 3.8 non-commercial version in win32. I get a big question. I Can't show PY variable in QT filedialog as initially parameter. Code sample is following:...
3
by: John Field | last post by:
Hello, Is it possible to exclude certain files in a wx.FileDialog, so that the user won't see them and can't select them with the mouse in de File open window? I was thinking of somehow...
4
by: Michael C# | last post by:
Does anyone know of any sample code for inheriting from the FileDialog or CommonDialog classes? I need to create a customized OpenFileDialog with some additional combo boxes on it. Thanks
2
by: zino | last post by:
I'm using the following code to get the file name and path, but after the user click the file, Excel open it. I don't want the Excel file to open, all I need is to get the file name that the user...
3
by: David Bib | last post by:
Although I'm relatively new to Access VBA, I've done a lot of macro programming in Excel VBA. The problem I'm having is that I get a 'User Type not defined' error at this line - Dim fd As...
3
blazedaces
by: blazedaces | last post by:
I've taken a look at the class and you only seem to be able to set the file name, but not it's save type. Why is this? Here's some code if you want it, but it doesn't seem to have a method for...
2
by: akmagnolia | last post by:
Hello- I am trying to use the FileDialog object to allow users to select a file. When I compile, I get the User type not defined error at the first DIM statement. My code is copied right out of the...
16
by: technocraze | last post by:
Hi pals, I would like to know how to display the FileName of the selected file in the textbox and open it using FileDialog property. I have imported the necessary reference from the library -...
2
jamjar
by: jamjar | last post by:
I am trying to use the SaveAs type FileDialog to allow the user to enter a file name. It's only letting me choose exisiting files. Is there any way to use the FileDialog to allow the user to select...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.