For Each objItem In colItems TRY cpt = cpt + 1 total = total + 1 Dim o As Redemption.SafeMailItem o = CreateObject("Redemption.SafeMailItem") o.Item = objItem Dim FileStr As String = sousrep + cpt.ToString("ad0000000000") + ".msg", Redemption.rdoSaveAsType.olRFC822 o.SaveAs(FileStr) 'C'est sur la ligne au dessus que ton fichier est enregistré donc c'est ici que l'erreur survient 'De plus c'est une System.Runtime.InteropServices.COMException <=== COM pour un composant com, ce qui veut dire que 'L'exception est bien généré par ton Ax. o = Nothing Retry: System.IO.File.SetLastWriteTime(FileStr, objItem.ReceivedTime) 'La ligne du dessus aussi une erreur d'accès peut être généré If objItem.unread Then System.IO.File.SetAttributes(FileStr, System.IO.FileAttributes.Hidden) End If Status.Text = "Traitement de [" + objFolder.Name + "] " + cpt.ToString + "/" + tot.ToString Me.Refresh() System.Windows.Forms.Application.DoEvents() Catch Ex As Exception 'Ici If Not TypeOf (ex) Is COMException Then If MsgBox ("Une erreur est survenue durant la création du fichier" & vbcr & FileStr, _ MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Erreur") = MsgBoxResult.Yes Then Goto Retry End If End If 'Attention cependent, si tu es tenté d'enlevé le message, fais gaffe à la boucle infinie en cas de coupure permanante de connexion. 'Idem, je t'ai donné un modèle, applique le même pour les erreurs éventuelles IO.File.. Next
System.IO.File.SetAttributes(FileStr, System.IO.FileAttributes.Hidden)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionTry retry2: o.SaveAs(sousrep + cpt.ToString("ad0000000000") + ".msg", Redemption.rdoSaveAsType.olRFC822) o = Nothing 'Changement de la date du fichier créé a la date du message System.IO.File.SetLastWriteTime(sousrep + cpt.ToString("ad0000000000") + ".msg", objItem.ReceivedTime) ' Si le fichier n'est pas lu on le met en caché If objItem.unread Then System.IO.File.SetAttributes(sousrep + cpt.ToString("ad0000000000") + ".msg", System.IO.FileAttributes.Hidden) End If Status.Text = "Traitement de [" + objFolder.Name + "] " + cpt.ToString + "/" + tot.ToString Me.Refresh() System.Windows.Forms.Application.DoEvents() Catch Ex As Exception If TypeOf (Ex) Is COMException Then ret = ret + 1 If ret < 4 Then GoTo Retry2 MsgBox("Une erreur est survenue au cour de la transformation du PST !" + vbCr + Ex.Message + vbCr + "L'application va se fermer") Me.Close() End If End Try
For Each objItem In colItems ' Ret = 0 cpt += 1 total += 1 ' Dim o As Redemption.SafeMailItem o = CreateObject("Redemption.SafeMailItem") o.Item = objItem ' Dim FileStr As String = _ sousrep + cpt.ToString("ad0000000000") + _ ".msg", Redemption.rdoSaveAsType.olRFC822 Try ' Retry: o.SaveAs(FileStr) Retry2: System.IO.File.SetLastWriteTime(FileStr, objItem.ReceivedTime) If objItem.unread Then System.IO.File.SetAttributes(FileStr, System.IO.FileAttributes.Hidden) End If Status.Text = "Traitement de [" + objFolder.Name + "] " + cpt.ToString + "/" + tot.ToString Me.Refresh() System.Windows.Forms.Application.DoEvents() Catch Ex As Exception ' If TypeOf (Ex) Is COMException Then ' ret += 1 If ret < 4 Then GoTo Retry MsgBox("Une erreur est survenue au cour de la transformation du PST !" + vbCr + _ Ex.Message + vbCr + "L'application va se fermer") Me.Close() ' ElseIf TypeOf (Ex) Is System.IO.DirectoryNotFoundException Then ' ret += 1 If ret < 4 Then GoTo Retry2 MsgBox("Une erreur est survenue au cour de la transformation du PST !" + vbCr + _ Ex.Message + vbCr + "L'application va se fermer") Me.Close() ' End If ' Finally ' o = Nothing ' End Try ' Next