Question Strange issue with WebClient and Windows 7..

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
I wrote a small application that uses webclient to download a zip file fromm the internet:
myWebClient.DownloadFile(myStringWebResource, downloadloc & fileName)

Next, I unzip the file and parse out the text file into a database. I'm using Windows 7 and the whole process works fine on my computer. The file is downloaded, I'm never prompted to "copy and replace" no matter how many times I download a new copy of the file..everything is perfect!

Here's where the problem is...A colleague of mine is located in Canada (I'm in the US) and he's also on Windows 7. When he tries to pull the zip file he DOES get prompted with a "copy and replace" box. When he presses that things seam to go okay and we can see that file gets unzipped. However, a little bit later in my code I do a check just to verify the file does exist and when that part of the code is called it throws back an error say the file doesn't exist! This is the part of code that is checking that:
If My.Computer.FileSystem.FileExists(downloadloc & unzipfile) Then
Do some stuff here...
Else
MsgBox("ERROR2: File does not exist! " & Now)
End If

So here is my question, why does the entire process work fine on my Windows 7 machine. Yet, on his not only does he get prompted to copy and replace the file, but he is also getting a messagebox saying the file doesn't even exist..When we can see that it does in fact exist!

Any help would be appreciated.
 
Thanks for the replies. Yes - both are downloading to the same location. which is in the AppData folder. Here is some of the code:

First thing I do is read in the file if it's already been downloaded before. If not, then we prompt that the file doesn't exist and the user will need to press the "Pull" button
VB.NET:
        If My.Computer.FileSystem.FileExists(newfile) = True Then
            Dim DomainDataTmp() As String = System.IO.File.ReadAllLines(newfile)
            length = DomainDataTmp.Length
            cnt = 1
            ReDim DomainData(length)
            While cnt < length
                DomainData(cnt) = DomainDataTmp(cnt)
                cnt = cnt + 1
            End While
        Else
            MsgBox("Needed files do not exist!  Please click on the Pull button.")
            filetest = False
        End If

Now, once he clicks the "Pull" button the first thing we do is get the file
VB.NET:
    Public Sub getfile()
        '===========================
        'Download file from web
        'filename variable is defined in the dim statement
        '===========================
        Dim myStringWebResource As String = Nothing
        ' Create a new WebClient instance.
        Dim myWebClient As New WebClient()

        'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
        myStringWebResource = remoteUri + fileName

        ' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
        myWebClient.DownloadFile(myStringWebResource, downloadloc & fileName)

        zipfile = myStringWebResource + fileName
        zipfilefolder = My.Computer.FileSystem.CurrentDirectory

    End Sub

Then we unzip the file which seams to work fine on his machine and mine
VB.NET:
    Sub UnZip()
        Dim ShellAppType As Type = Type.GetTypeFromProgID("Shell.Application")
        Dim sc As Object = Activator.CreateInstance(ShellAppType)
        Dim dir_name As String = Application.StartupPath

        'Create directory in which you will unzip your files .
        If System.IO.Directory.Exists(downloadloc) Then
            'nothing
        Else
            IO.Directory.CreateDirectory(downloadloc)
        End If

        'Declare the folder where the files will be extracted
        Dim output As Shell32.Folder = sc.NameSpace(downloadloc.ToString)
        'Declare your input zip file as folder  .
        Dim input As Shell32.Folder = sc.NameSpace(downloadloc.ToString & fileName.ToString)
        '========If file exist delete it =====
        If My.Computer.FileSystem.FileExists(downloadloc & unzipfile) Then
            Kill(downloadloc & unzipfile)
        Else
            'do nothing at this time
        End If
        '=====================================
        'Extract the files from the zip file using the CopyHere command .
        output.CopyHere(input.Items, 4)
        unzipfile = input.Title & ".txt"      'Needed for unzipped file name
        FolderFilePath = downloadloc & unzipfile

    End Sub

After it's unzipped it is then being read into an array. This is where things seam to stop for him. He always get the else msgbox portion here.
VB.NET:
    Public Sub readinfile()
        'Read in downloaded file and create an array from it
        'DomainData() is the main array that contains the entire list of domains
        'DomainDataTmp() is the array the orginal file is read into used ONLY in this sub.

        If My.Computer.FileSystem.FileExists(downloadloc & unzipfile) Then
            Dim DomainDataTmp() As String = System.IO.File.ReadAllLines(downloadloc & unzipfile)
            length = DomainDataTmp.Length
            cnt = 1
            ReDim DomainData(length)
            ReDim DomainDataFiltered(length)

            While cnt < length
                DomainData(cnt) = DomainDataTmp(cnt)
                cnt = cnt + 1
            End While
        Else
            MsgBox("ERROR2: File does not exist!  " & Now)
            errorflag1 = True
        End If
    End Sub
 
Back
Top