Hier nun der Code für das Formular
Imports Microsoft.Office.Interop
Public Class Form1
Const Dateipfad As String = "C:\tmp\Test.msg"
Sub ändern(Dateipfad As String, neuesDatum As Date)
Dim sFile As String = Dateipfad
' FileInfo-Objekt erstellen
With New System.IO.FileInfo(sFile)
' Datums- und Zeitangaben auslesen
Debug.Print("Erstellungsdatum: " & .CreationTime)
Debug.Print("Letzter Zugriff: " & .LastAccessTime)
Debug.Print("Letzte Änderung: " & .LastWriteTime)
' Erstellungsdatum ändern
Dim DatumTag As Integer
'DatumTag = DateTime.Parse(neuesDatum.Day).DayOfWeek
.CreationTime = New Date(neuesDatum.Year, neuesDatum.Month, _
neuesDatum.Day, neuesDatum.Hour, neuesDatum.Minute, _
neuesDatum.Second)
' Datumsangabe "Letzter Zugriff" ändern
.LastAccessTime = neuesDatum ' New Date(2009, 5, 16, 13, 12, 11)
' Datum "Letzte Änderung" ändern
.LastWriteTime = neuesDatum ' New Date(2009, 5, 17, 13, 12, 11)
End With
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) _
Handles Button2.Click
Dim objOutlook As Outlook.Application
Dim objOutlookItem As Outlook.MailItem
Dim NeuesDatum As Date
' Erzeugen...
objOutlook = New Outlook.Application
' Check...
If Not objOutlook Is Nothing Then
' Ab hier könntest Du eine Schleife draus machen,
' um die Dateien alle einzulesen
'
' Mail öffnen...
objOutlookItem = CType(objOutlook.Session.OpenSharedItem( _
Dateipfad), Outlook.MailItem) 'strPath & "\" & strFile)
' Check...
If Not objOutlookItem Is Nothing Then
' Auslesen...
'MsgBox "Body: " & objOutlookItem.Body
'MsgBox "CreationTime: " & objOutlookItem.CreationTime
'MsgBox "DeferredDeliveryTime: " &
' objOutlookItem.DeferredDeliveryTime
MsgBox("ReceivedTime: " & objOutlookItem.ReceivedTime)
'MsgBox "ReminderTime: " & objOutlookItem.ReminderTime
MsgBox("SenderName: " & objOutlookItem.SenderName)
MsgBox("SenderEmailAddress: " & _
objOutlookItem.SenderEmailAddress)
MsgBox("Subject: " & objOutlookItem.Subject)
NeuesDatum = objOutlookItem.ReceivedTime
' Schließen...
' Hie scheint es dran zu liegen
'objOutlookItem.Close(Outlook.OlInspectorClose.olDiscard) ' _
Close(olDiscard) ' 1 = Discard = Verwerfen
'Outlook.Application.close()
releaseObj(objOutlookItem)
End If
' Zurücksetzen...
objOutlookItem = Nothing
'
' Hier wäre das Ende der Schleife
'
' Abschließen schließen...
objOutlook.Quit()
End If
' Aufräumen...
objOutlook = Nothing
Try
Catch ex As Exception
End Try
Call ändern(Dateipfad, NeuesDatum)
End Sub
Private Sub releaseObj(objOutlookItem As Outlook.MailItem)
Throw New NotImplementedException
End Sub
End Class Für die Klasse cls_Outlook
Imports Microsoft.Win32.SafeHandles
Imports System
Imports System.Runtime.InteropServices
Class cls_Outlook
Implements IDisposable
Private disposed As Boolean = False
Private handle As SafeHandle = New SafeFileHandle(IntPtr.Zero, True)
Public Sub Dispose()
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If disposed Then Return
If disposing Then
handle.Dispose()
End If
disposed = True
End Sub
Public Sub ReleaseObj(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
Catch
Finally
obj = Nothing
End Try
End Sub
End Class |