Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 BackgroundWorker and FTP FileUpload issue

$
0
0
Hi there,

This is the section of code that is giving me an error:

vb Code:
  1. Private Sub bgw_UploadZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_UploadZip.DoWork
  2.         'Uploads complete .zip file via FTP to client location
  3.         My.Computer.Network.UploadFile(System.IO.Path.GetTempPath & ZipFilename & ".zip", "ftp://domain.com" & ZipFilename & ".zip", "user", "pass", FileIO.UIOption.AllDialogs, 100, FileIO.UICancelOption.DoNothing)
  4.     End Sub

The error is as follows:

"Unable to cast object of type 'System.ComponentModel.AsyncOperation' to type 'UploadBitsState'"

The thing is, it works fine on the x64 Windows 7 machine, but when running on x86 Windows XP is errors.

All of the BackgroundWorkers I'm using/linking are as follows. Any help would be greatly appreciated:

vb Code:
  1. Private Sub bgw_CopyDocs_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_CopyDocs.DoWork
  2.         MsgBox("Copy")
  3.         'Copies all files into a temporary folder to be zipped
  4.         For Each row As DataGridViewRow In frm_TMDocumentReview.dgv_TMDocumentReview.Rows
  5.             Try
  6.                 My.Computer.FileSystem.CopyFile(CurrentProjectsLocation & "\" & _
  7.                                                 tbx_Client.Text & "\" & _
  8.                                                 tbx_JobNo.Text & " - " & tbx_JobTitle.Text & "\" & _
  9.                                                 row.Cells("Category = DC Level 4").Value.ToString & "\" & _
  10.                                                 row.Cells("Discipline = DC Level 5").Value.ToString & "\" & _
  11.                                                 row.Cells("Document Type 1 = DC Level 6").Value.ToString & "\" & _
  12.                                                 row.Cells("Document Type 2 = DC Level 7").Value.ToString & "\" & _
  13.                                                 row.Cells("Filename").Value.ToString & _
  14.                                                 row.Cells("File Extension").Value.ToString, System.IO.Path.GetTempPath & TempTMID & "\" & row.Cells("Filename").Value.ToString & row.Cells("File Extension").Value.ToString)
  15.             Catch ex As Exception
  16.                 MsgBox("File does not exist:" & vbNewLine _
  17.                        & vbNewLine _
  18.                        & ex.ToString)
  19.             End Try
  20.         Next
  21.         MsgBox("Copy complete")
  22.     End Sub
  23.  
  24.     Private Sub bgw_CopyDocs_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_CopyDocs.RunWorkerCompleted
  25.         If e.Cancelled = True Then
  26.  
  27.         ElseIf e.Error IsNot Nothing Then
  28.             MsgBox("(Test4) - Error: " & e.Error.Message)
  29.         Else
  30.             'Starts backgroundworker to create zipfile
  31.             If bgw_CreateZip.IsBusy <> True Then
  32.                 bgw_CreateZip.RunWorkerAsync()
  33.             End If
  34.         End If
  35.     End Sub
  36.  
  37.     Private Sub bgw_CreateZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_CreateZip.DoWork
  38.         Try
  39.  
  40.             'Process.Start("explorer.exe", System.IO.Path.GetTempPath & TempTMID)
  41.  
  42.             'The following data represents an empty zip file .
  43.             Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, _
  44.                                             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  45.             'Data for an empty zip file .
  46.             FileIO.FileSystem.WriteAllBytes(System.IO.Path.GetTempPath & ZipFilename & ".zip", startBuffer, False)
  47.  
  48.             'Declare new shell class
  49.             'Dim sc As New Shell32.Shell()
  50.             Dim ShellAppType As Type = Type.GetTypeFromProgID("Shell.Application")
  51.             Dim sc As Object = Activator.CreateInstance(ShellAppType)
  52.  
  53.             'Declare the folder which contains the files you want to zip .
  54.             Dim input As Shell32.Folder = sc.NameSpace(System.IO.Path.GetTempPath & TempTMID)
  55.  
  56.             'Declare  your created empty zip file as folder  .
  57.             Dim output As Shell32.Folder = sc.NameSpace(System.IO.Path.GetTempPath & ZipFilename & ".zip")
  58.  
  59.             'Copy the files into the empty zip file using the CopyHere command .
  60.             output.CopyHere(input.Items, 4)
  61.  
  62.             Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
  63.             worker.ReportProgress(10)
  64.         Catch ex As Exception
  65.             MessageBox.Show(ex.ToString)
  66.         End Try
  67.     End Sub
  68.  
  69.     Private Sub bgw_CreateZip_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_CreateZip.RunWorkerCompleted
  70.         If e.Cancelled = True Then
  71.  
  72.         ElseIf e.Error IsNot Nothing Then
  73.             MsgBox("(Test3) - Error: " & e.Error.Message)
  74.         Else
  75.             Dim ConfirmUpload = MsgBox("The documents will now be uploaded.", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Upload Transmittal Documents")
  76.             If ConfirmUpload = DialogResult.Cancel Then
  77.                 Exit Sub
  78.             ElseIf ConfirmUpload = DialogResult.OK Then
  79.                 'Starts backgroundworker to upload zipped files
  80.                 If bgw_UploadZip.IsBusy <> True Then
  81.                     bgw_UploadZip.RunWorkerAsync()
  82.                 End If
  83.             End If
  84.  
  85.         End If
  86.     End Sub
  87.  
  88.     Private Sub bgw_UploadZip_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_UploadZip.DoWork
  89.         'Uploads complete .zip file via FTP to client location
  90.         My.Computer.Network.UploadFile(System.IO.Path.GetTempPath & ZipFilename & ".zip", "ftp://domain.com" & ZipFilename & ".zip", "user", "Tpass", FileIO.UIOption.AllDialogs, 100, FileIO.UICancelOption.DoNothing)
  91.     End Sub
  92.  
  93.     Private Sub bgw_UploadZip_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_UploadZip.RunWorkerCompleted
  94.         If e.Cancelled = True Then
  95.  
  96.         ElseIf e.Error IsNot Nothing Then
  97.             MsgBox("(Test2) - Error: " & e.Error.Message)
  98.         Else
  99.             MsgBox("The documents within this transmittal have been uploaded successfully." & vbNewLine _
  100.                    & vbNewLine _
  101.                    & ZipFilename & ".zip", MsgBoxStyle.Information, "Documentation Upload")
  102.  
  103.             'Starts backgroundworker to prepare email
  104.             If bgw_PrepEmail.IsBusy <> True Then
  105.                 bgw_PrepEmail.RunWorkerAsync()
  106.             End If
  107.         End If
  108.     End Sub
  109.  
  110.     Private Sub bgw_PrepEmail_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bgw_PrepEmail.DoWork
  111.         Dim olApp As Object
  112.         olApp = CreateObject("Outlook.Application")
  113.         If olApp IsNot Nothing Then
  114.             Dim olEmail As New Object
  115.             olEmail = olApp.CreateItem(0)
  116.             olEmail.To = Transmittal_SelectedRecipients_Emails
  117.             olEmail.Subject = "Transmittal: " & Transmittal_TMNo & " (" & Transmittal_JobNo & " - " & Transmittal_JobTitle & ")"
  118.             olEmail.HTMLBody = "<p style = 'font-family: Calibri; font-size: 11pt;'>Please find document transmittal " & Transmittal_TMNo & " attached.<br><br>" & _
  119.                             "Use the link below to download the documents in this transmittal.<br>" & _
  120.                             "<a href='http://www.domain.com/" & ZipFilename & ".zip'>Click to download</a></p>"
  121.             olEmail.Attachments.Add(NewDocument_Location & ".pdf")
  122.             olEmail.Display(True)
  123.         End If
  124.     End Sub
  125.  
  126.     Private Sub bgw_PrepEmail_RunWorkerCompleted(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw_PrepEmail.RunWorkerCompleted
  127.         GenerateDocNo()
  128.         cbx_TMDesc.Text = ""
  129.         tbx_Comments.Text = ""
  130.         cbx_Company.Text = ""
  131.         cbx_TMDesc.Select()
  132.         ResetVariablesTM()
  133.         dgv_TMDocuments.DataSource = Nothing
  134.     End Sub

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>