locked
Copy.Doc or .xls or .pdf file website RRS feed

  • Question

  • User1480781148 posted

    Hi Friends,

    As I want to copy  .Doc or .xls or .pdf from website please help me how I can copy to my local ftp server , the path will be as followed

    http://www.xyz/cv.doc

    thank you.

    Regards,

    Asad

    Tuesday, December 16, 2014 12:48 AM

Answers

  • User1480781148 posted

    hi, 

    Please I tested the following code working perfectly.  thank you.

    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    DownloadFile("http://www.xyz.com/wp-content/uploads/career/resume/1378993138-cv.docx", "C:\\testt\1378993138-cv.docx)

    End Sub

    Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)

    Try

    Dim _WebClient As New System.Net.WebClient()

    ' Downloads the resource with the specified URI to a local file.

    _WebClient.DownloadFile(_URL, _SaveAs)

    Catch _Exception As Exception

    ' Error

    Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())

    End Try

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 17, 2014 12:46 AM

All replies

  • User541108374 posted

    Hi,

    do you want to make use of FTP from your application or do you have a UNC share to which you can copy files to from your application? If the latter's the case take a look at File class in the System.IO namespace.

    For an example take a look at the MSDN documentation: http://msdn.microsoft.com/en-us/library/c6cfw35a(v=vs.110).aspx.

    Grz, Kris.

    Tuesday, December 16, 2014 12:59 AM
  • User1480781148 posted

    thank you for reply,  i am receiving following error 

    {"URI formats are not supported."}

    thank you.

    regards,

    Tuesday, December 16, 2014 2:35 AM
  • User541108374 posted

    Hi,

    thank you for reply,  i am receiving following error 

    {"URI formats are not supported."}

    How, what, where, code? Which approach are you using? In which part of the code do you get this exception? What's the content of the variable that's providing the error? Did you make up your path correctly, ... ?

    Grz, Kris.

    Tuesday, December 16, 2014 2:41 AM
  • User1480781148 posted

    Please find below my code

    Dim sourceDir As String = "http://xyz.com/wp-content/uploads/career/resume/"
    Dim backupDir As String = "c:\cvtest"

    Try
    Dim picList As String() = Directory.GetFiles(sourceDir, "*.jpg")
    Dim txtList As String() = Directory.GetFiles(sourceDir, "*.*")

    ' Copy picture files.
    For Each f As String In picList
    'Remove path from the file name.
    Dim fName As String = f.Substring(sourceDir.Length + 1)

    ' Use the Path.Combine method to safely append the file name to the path.
    ' Will overwrite if the destination file already exists.
    File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), True)
    Next

    ' Copy text files.
    For Each f As String In txtList

    'Remove path from the file name.
    Dim fName As String = f.Substring(sourceDir.Length + 1)

    Try
    ' Will not overwrite if the destination file already exists.
    File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName))

    ' Catch exception if the file was already copied.
    Catch copyError As IOException
    Console.WriteLine(copyError.Message)
    End Try
    Next

    For Each f As String In txtList
    File.Delete(f)
    Next

    For Each f As String In picList
    File.Delete(f)
    Next

    Catch dirNotFound As DirectoryNotFoundException
    Console.WriteLine(dirNotFound.Message)
    End Try

    thank you.

    regards,

    Tuesday, December 16, 2014 2:44 AM
  • User541108374 posted

    Hi,

    which part of your code goes wrong? Did you check the needed privileges for the folder to be copied to? That the account your application is running under has the needed privileges as well to write in that folder? By default this is all locked down for security reasons.

    Grz, Kris.

    Tuesday, December 16, 2014 2:53 AM
  • User1480781148 posted

    Hi, 

    I checked like following url pasting in browser file start downloading means no issue with permissions. 

    www.xyz.com/mycv.doc

    thank you.

    regards,

    Tuesday, December 16, 2014 4:01 AM
  • User541108374 posted

    Hi,

    I checked like following url pasting in browser file start downloading means no issue with permissions. 

    It's the web application and under which user it runs that needs the permissions to write to the disk. Opening it via a browser is a completely different thing.

    Grz, Kris.

    Tuesday, December 16, 2014 4:12 AM
  • User1480781148 posted

    thank you for reply, windows users has administrator password. further it is running as default.

    thank you.

    Regards,

    Wednesday, December 17, 2014 12:23 AM
  • User1480781148 posted

    hi, 

    Please I tested the following code working perfectly.  thank you.

    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    DownloadFile("http://www.xyz.com/wp-content/uploads/career/resume/1378993138-cv.docx", "C:\\testt\1378993138-cv.docx)

    End Sub

    Public Sub DownloadFile(ByVal _URL As String, ByVal _SaveAs As String)

    Try

    Dim _WebClient As New System.Net.WebClient()

    ' Downloads the resource with the specified URI to a local file.

    _WebClient.DownloadFile(_URL, _SaveAs)

    Catch _Exception As Exception

    ' Error

    Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())

    End Try

    End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 17, 2014 12:46 AM