CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2013
    Posts
    28

    FTP site on webbrowser1 control select the file and download it.

    FTPLoadUpDown-De.zip

    Hi All

    Can any 1 help me with this please.

    1.I select the any1 file on the webbrowser1 control then i click on "Download from FTP" button but its not
    at all working please help me out my friends.

    1. When i click on the FTP upload i should be able to upload up to 50MB. and it should download a little fast but not super fast.
    2. when i am uploading or downloading the cursor should be lokking like "Hourse shoe"

    Its very urgent.

    The project i uploaded here, u can find it. well inside it there were setupfiles i removed it as the size was big it was telling me. so.

    please help me out.

    Regards
    SeemaFTPLoadUpDown-De.zip

  2. #2
    Join Date
    Jan 2013
    Posts
    28

    Re: FTP site on webbrowser1 control select the file and download it.

    forums.codeguru.com/showthread.php?542001-How-to-Download-from-FTP-site-with-Webbrowser1-control

    thats a same thread with another attachment, as i am unable to attach it here, plz do refer it.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: FTP site on webbrowser1 control select the file and download it.

    Nobody is going to do your work for you. What we can do is look over code that might be an issue, and point you in the right direction.
    Posting multiple threads with downloads does not constitute any work on your part that we can help with.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Jan 2013
    Posts
    28

    Re: FTP site on webbrowser1 control select the file and download it.

    Hi David,

    I have already done most of the things in this program.
    I am just asking how to do the following things:
    1)Like it should load till 50MB. This one I really dnt no.
    2)When I select a file on webbrowser1 control n click “download From FTP” button then it should get downloaded in to the path specified. PLz look in to the code i wrote.
    3) in the comments I have even wrote the code for download that’s also not working what I do…. I am some where wrong help me friends, Please.
    I have written the code but its not working,
    Ok here is the code, plz help me to correct it,
    Code:
     
    
    PrivateSubBtn_Download_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlesBtn_Download.Click
    'Dim elementname As String
    'Dim id As String
    'Dim innertext As String
    'Dim outertext As String
    'Dim innerhtml As String
    'Dim outerhtml As String
            WebBrowser1.Document.ActiveElement.InnerText = "hello"
    MsgBox(WebBrowser1.Document.All.GetElementsByName("q").Item(0).GetAttribute("value").ToString)
    'Dim strfilename As String = WebBrowser1.Document.Window
    
    
    
    Dim elements AsInteger = WebBrowser1.Document.All.Count
    
    Dim x = WebBrowser1.Document.ActiveElement
    If x IsNotNothingThen
    
    DimfileUrlAsString = x.GetAttribute("href")
    EndIf
    
    
    
    
    Dim Temp1, Temp2
    Dimi = 0
            Temp1 = WebBrowser1.Document.All.Item(i).Name
            Temp2 = WebBrowser1.DocumentText.ToString.ToLower()
    
    'If TxtDownFileName.Text = " " Then
    '    MsgBox("Please enter the File name to be downloaded")
    'End If
    
    'If TxtDownloadPath.Text = " " Then
    '    MsgBox("Please select the Directory ")
    'End If
    
    
    'Values to use
    'Dim localFile As String = PvCS_FoldName + "\" + TxtDownFileName.Text
    'Dim remoteFile As String = "/" + TxtDownFileName.Text
    'Dim host As String = TxtFTPSite.Text
    Const username AsString = ""
    Const password AsString = ""
    
    '  If (TxtDownFileName.Text.Length = 0 Or TxtDownloadPath.Text.Length = 0) Then
    '    MessageBox.Show("Download File name and Download Path Must be given")
    '    Return
    'End If
    'If Not IO.Directory.Exists(TxtDownloadPath.Text) Then
    '    MessageBox.Show("Selected Download path doesn't exists")
    '    Return
    'End If
    '1. Create a request: must be in ftp://hostname format, 
    '   not just ftp.myhost.com
    ' Dim URI As String = host &remoteFile
    'Dim ftp AsSystem.Net.FtpWebRequest = _
    '    CType(FtpWebRequest.Create(URI), FtpWebRequest)
    
    '2. Set credentials
    'ftp.Credentials = New  _
    '    System.Net.NetworkCredential(username, password)
    
    ''''''''added now for progress bar
    'Dim a As String
    'a = TxtFTPSite.Text + TxtDownFileName.Text
    'For offset As Integer = 0 To FileLen(a) Step 1024
    '    ProgressBar2.Value = CType(offset * ProgressBar2.Maximum / FileLen(a), Integer)
    '    Dim chunkSize As Integer = FileLen(a) - offset - 1
    '    If chunkSize> 1024 Then chunkSize = 1024
    '    '  strz.Write(PvS_FileName, offset, chunkSize)
    '    ProgressBar2.Value = ProgressBar2.Maximum
    'Next
    
    '////////////////////////////////
    'Dim clsRequest As System.Net.FtpWebRequest = _
    'DirectCast(System.Net.WebRequest.Create(TxtFTPSite.Text + TxtDownFileName.Text), System.Net.FtpWebRequest)  'this line is commented by Seema
    
    Dim _Html AsString
            _Html = WebBrowser1.Document.Body.InnerHtml
    
    ' DimclsRequest As System.Net.FtpWebRequest = _
    'DirectCast(System.Net.WebRequest.Create(TxtFTPSite.Text + TxtDownFileName.Text), System.Net.FtpWebRequest)  'this line is commented by Seema
    
    ' clsRequest.Credentials = New System.Net.NetworkCredential("", "")
    'clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
    ''rfshTMR.Enabled = True
    DimFile() AsByte = System.IO.File.ReadAllBytes(TxtPath.Text)
    ' DimclsStream As System.IO.Stream = _
    'clsRequest.GetRequestStream()
    'clsStream.Write(File, 0, File.Length)
    'For offset As Integer = 0 To File.Length Step 1024
    '    ProgressBar2.Value = CType(offset * ProgressBar2.Maximum / File.Length, Integer)
    '    Dim chunkSize As Long = File.Length - offset - 1
    '    'Dim chunkSize As Double = File.Length - offset - 1
    '    If chunkSize> 1024 Then chunkSize = 1024
    '    clsStream.Write(File, offset, chunkSize)
    '    ProgressBar2.Value = ProgressBar2.Maximum
    'Next
    'clsStream.Close()
    'clsStream.Dispose()
    
    
    
    '3. Settings and action
    'ftp.KeepAlive = False
    ''we want a binary transfer, not textual data
    'ftp.UseBinary = True
    
    ''Define the action required (in this case, download a file)
    'ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
    
    
    MessageBox.Show("Selected File Downloaded Succefully from FTP Site")
    
            WebBrowser2.Url = NewUri(TxtDownloadPath.Text)
    
    EndSub
    All friends please check my attachment.
    Thanks in Advance

    Seema

    Quote Originally Posted by dglienna View Post
    Nobody is going to do your work for you. What we can do is look over code that might be an issue, and point you in the right direction.
    Posting multiple threads with downloads does not constitute any work on your part that we can help with.

  5. #5
    Join Date
    Jan 2013
    Posts
    28

    Re: FTP site on webbrowser1 control select the file and download it.

    Hi all,

    Just bnow i wrote another program for download, but its not working properly.

    I am attaching my program, from morning i have tried please look in to it. And guide me.

    Code:
      
    Imports System.Net
    
    PublicClassForm1
    DimwhereToSaveAsString
    DelegateSubChangeTextsSafe(ByVal length AsLong, ByVal position AsInteger, ByVal percent AsInteger, ByVal speed AsDouble)
    DelegateSubDownloadCompleteSafe(ByVal cancelled AsBoolean)
    
    PublicSubDownloadComplete(ByVal cancelled AsBoolean)
    Me.Label1.Text = "Successfully downloaded"
    MessageBox.Show("Successfully downloaded!", "All OK", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Me.ProgressBar1.Value = 0
    EndSub
    PublicSubChangeTexts(ByVal length AsLong, ByVal position AsInteger, ByVal percent AsInteger, ByVal speed AsDouble)
    
    Me.Label3.Text = "File Size: "&Math.Round((length / 1024), 2) &" KB"
    
    Me.Label5.Text = "Downloading: "&Me.TextBox1.Text
    
    Me.Label4.Text = "Downloaded "&Math.Round((position / 1024), 2) &" KB of "&Math.Round((length / 1024), 2) &"KB ("&Me.ProgressBar1.Value &"%)"
    
    If speed = -1 Then
    Me.Label2.Text = "Speed: calculating..."
    Else
    Me.Label2.Text = "Speed: "&Math.Round((speed / 1024), 2) &" KB/s"
    EndIf
    
    Me.ProgressBar1.Value = percent
    
    
    EndSub
    
    PrivateSub Button1_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
    IfMe.TextBox1.Text <>""AndAlsoMe.TextBox1.Text.StartsWith("ftp://") Then
    '  Me.SaveFileDialog1.FileName = Me.txtFileName.Text.Split("/"c)(Me.txtFileName.Text.Split("/"c).Length - 1)
    
    IfMe.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OKThen
    Me.whereToSave = Me.SaveFileDialog1.FileName
    Me.SaveFileDialog1.FileName = ""
    
    ''  Me.Label6.Text = "Save to: " &Me.whereToSave
    
    'Me.txtFileName.Enabled = False
    'Me.btnDownload.Enabled = False
    'Me.btnCancel.Enabled = True
    
    Me.BackgroundWorker1.RunWorkerAsync() 'Start download
    
    EndIf
    
    Else
    
    MessageBox.Show("Please insert valid URL for download", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    
    EndIf
    
    EndSub
    
    PrivateSub BackgroundWorker1_DoWork(ByVal sender AsSystem.Object, ByVal e AsSystem.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    'Creating the request and getting the response
    DimtheResponseAsHttpWebResponse
    DimtheRequestAsHttpWebRequest
    Try'Checks if the file exist
    
    theRequest = WebRequest.Create(Me.TextBox1.Text)
    theResponse = theRequest.GetResponse
    Catch ex AsException
    
    MessageBox.Show("An error occurred while downloading file. Possibe causes:"&ControlChars.CrLf& _
    "1) File doesn't exist"&ControlChars.CrLf& _
    "2) Remote server error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
    
    Exit Sub
    EndTry
    Dim length AsLong = theResponse.ContentLength'Size of the response (in bytes)
    
    DimsafedelegateAsNewChangeTextsSafe(AddressOfChangeTexts)
    Me.Invoke(safedelegate, length, 0, 0, 0) 'Invoke the TreadsafeDelegate
    
    DimwriteStreamAsNewIO.FileStream(Me.whereToSave, IO.FileMode.Create)
    
    'Replacement for Stream.Position (webResponse stream doesn't support seek)
    DimnReadAsInteger
    
    'To calculate the download speed
    DimspeedtimerAsNewStopwatch
    DimcurrentspeedAsDouble = -1
    Dim readings AsInteger = 0
    
    Do
    
    If BackgroundWorker1.CancellationPending Then'If user abort download
    Exit Do
    EndIf
    
    speedtimer.Start()
    
    DimreadBytes(4095) AsByte
    DimbytesreadAsInteger = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
    
    nRead += bytesread
    Dim percent AsShort = (nRead * 100) / nRead
    'Dim percent As Short = (nRead * 100) / length
    
    Me.Invoke(safedelegate, length, nRead, percent, currentspeed)
    
    Ifbytesread = 0 ThenExit Do
    
    writeStream.Write(readBytes, 0, bytesread)
    
    speedtimer.Stop()
    
    readings += 1
    If readings >= 5 Then'For increase precision, the speed it's calculated only every five cicles
    currentspeed = 20480 / (speedtimer.ElapsedMilliseconds / 1000)
    speedtimer.Reset()
    readings = 0
    EndIf
    Loop
    
    'Close the streams
    theResponse.GetResponseStream.Close()
    writeStream.Close()
    
    
    
    DimcompleteDelegateAsNewDownloadCompleteSafe(AddressOfDownloadComplete)
    
    Me.Invoke(completeDelegate, False)
    
    EndSub
    
    PrivateSub Invoke(ByValsafedelegateAsChangeTextsSafe, ByVal length AsLong, ByVal p3 AsInteger, ByVal p4 AsInteger, ByVal p5 AsInteger)
    ThrowNewNotImplementedException
    EndSub
    
    
    PrivateSub Label1_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles Label1.Click
    
    EndSub
    
    PrivateSubInvoke(ByValcompleteDelegateAsDownloadCompleteSafe, ByVal p2 AsBoolean)
    ThrowNewNotImplementedException
    EndSub
    
    PrivateSubupload_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesupload.Click
    IfMe.TxtUFTPPath.Text<>""AndAlsoMe.TxtUFTPPath.Text.StartsWith("ftp://") Then
    
                WebBrowser1.Url = NewUri(TxtUFTPPath.Text)
    
    'credientials = New NetworkCredential(" ", " ", " ")
    MessageBox.Show("Please provide the user name and password!")
    
    
    MessageBox.Show("You are connected to FTP Server")
    
    '  Me.BackgroundWorker1.RunWorkerAsync()
    
    Else
    
    MessageBox.Show("Please insert valid FTP URL for download", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    
    EndIf
    EndSub
    
    PrivateSubTxtUFTPPath_TextChanged(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlesTxtUFTPPath.TextChanged
    
    EndSub
    
    PrivateSub Form1_Load(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) HandlesMyBase.Load
    
    EndSub
    EndClass

  6. #6
    Join Date
    Jan 2013
    Posts
    28

    Re: FTP site on webbrowser1 control select the file and download it.

    WindowsApplication1.zip

    Plz chk it out.

    I have written the code, in order to understand the design i have attached the program.

    Hope i will get so,e help from u.

    Main problemis how to select a file from webbrowser control? and save the it to a string variable?

    is this the way?
    Code:
    Dim x = WebBrowser1.Document.ActiveElement

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured