|
-
May 1st, 2007, 11:58 AM
#1
Thread Starter
New Member
[RESOLVED] [2005] Removing filename from path string
I am creating an application that downloads a file, copies the old file to c:/sdk/backup (after check if this folder exists) then it moves the downloaded file to the location of the original file.
The location of the original file is variable, the user has 2 options: leave the default path in a textbox or choose openfiledialog to put a new path in the same box.
Before moving the downloaded file to the original location I would like to check if indeed this path exists. If I now change the default location to Z:/blablabla then the program crashes with an I/O exeption.
I now use this:
Code:
Dim bestandsnaam = TextBoxLocatie.Text.Substring(TextBoxLocatie.Text.LastIndexOf("\") + 1)
(dutch for filename)
Now I would like to do something like this:
Code:
Dim ftdlocatiedir As String = TextBoxLocatie.Text.Substring(TextBoxLocatie.Text - bestandsnaam)
Unfortunately such coding does not exist. Can anyone help me with this?
the goal is to make this work (now I do not have a valid string for the ftdlocatiedir).
Code:
If Not IO.Directory.Exists(ftdlocatiedir.Text) Then
MessageBox.Show("Not a valid directory to download to, please pick a valid directory", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
Else
File.Copy(downloadlocatie, ftdlocatie)
LabelFinish.Visible = True
LabelFinish.Text = "Nieuwe post bestand geplaatst, Start FTD!"
End If
Thanks in advance (!).
-
May 1st, 2007, 12:05 PM
#2
Re: [2005] Removing filename from path string
Use the IO.Path class
Code:
Dim filePathOnly As String = IO.Path.GetDirectoryName("C:\somefolder\subfolder\test\test.txt")
MsgBox(filePathOnly)
-
May 1st, 2007, 12:42 PM
#3
Thread Starter
New Member
Re: [2005] Removing filename from path string
 Originally Posted by stanav
Use the IO.Path class
Code:
Dim filePathOnly As String = IO.Path.GetDirectoryName("C:\somefolder\subfolder\test\test.txt")
MsgBox(filePathOnly)
Ok thanks it works .
I am noticing some strange behavior though with the download script. I replaced the default download script I used with one of this forum that included a progress bar
http://www.vbforums.com/showthread.php?t=396260
Original code I used before:
Code:
Protected Sub DownloadWebFile(ByVal remoteFile As String, ByVal localFile As String)
LabelDownload.Text = "Download gestart"
Dim localFileStream As New FileStream(localFile, FileMode.OpenOrCreate)
Dim myRequest As WebRequest = WebRequest.Create(remoteFile)
myRequest.Method = WebRequestMethods.Http.Get
Dim myResponse As WebResponse = myRequest.GetResponse
Dim myResponseStream As Stream = myResponse.GetResponseStream
Dim buffer(1024) As Byte
Dim bytesRead As Integer = myResponseStream.Read(buffer, 0, 1024)
While bytesRead > 0
localFileStream.Write(buffer, 0, bytesRead)
bytesRead = myResponseStream.Read(buffer, 0, 1024)
End While
LabelDownload.Text = "Download gelukt"
localFileStream.Close()
myResponseStream.Close()
End Sub
With the code from the forum the file downloads really slow in the beginning (untill 50%) after this it goes from 60-100 kbps to 700 kbps. 800 should be no problem...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|