Benutzer mit den meisten Antworten
Outlook-Attachments in Aplikation

Frage
-
Hallo Leute,
hat jemand irgendwo ein Beispiel wie ich OL 2010-Attachments per Drag&Drop oder auch per Zwischenablage (Strg+C) in eine Anwendung kopieren kann?
Ich habe ein Beispiel mit der kann ich aber immer nur eine Datei kopieren. Ich möchte aber gerne mehrere Dateien auf einmal kopieren.
Vielen Dank im Voraus.
Gruß Ahmed
Antworten
-
Hallo Leute,
endlich habe ich die Lösung gefunden und es funktioniert einwandfrei.
Ich kann jetzt auch endlich alle seletkierten Anlagen auf einmal speichern.
Hier der Code:
If DTO.GetDataPresent("FileDrop") Then For i = 0 To DTO.GetFileDropList.Count - 1 sFileName = System.IO.Path.GetFileName(DTO.GetFileDropList(i).ToString) SubItem = lvwFile.Items.Add(sFileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(DTO.GetFileDropList(i).ToString).LastWriteTime) System.IO.File.Move(DTO.GetFileDropList(i).ToString, sPfad & "\" & sFileName) Next ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then Dim objOL As New Outlook.Application Dim myobj As Outlook.MailItem Dim objAtt As Outlook.AttachmentSelection = objOL.ActiveExplorer.attachmentselection If objAtt.Count = 0 Then 'Attachtments selectiert (0=Nein) For i = 1 To objOL.ActiveExplorer.Selection.Count myobj = objOL.ActiveExplorer.Selection.Item(i) sFileName = CleanFilename(myobj.Subject & ".msg") myobj.SaveAs(IO.Path.Combine(sPfad, sFileName)) SubItem = lvwFile.Items.Add(sFileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(IO.Path.Combine(sPfad, sFileName)).LastWriteTime) Next Else For i = 1 To objAtt.Count objAtt(i).SaveAsFile(IO.Path.Combine(sPfad, objAtt(i).FileName)) SubItem = lvwFile.Items.Add(objAtt(i).FileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(IO.Path.Combine(sPfad, objAtt(i).FileName)).LastWriteTime) Next End If
Das könnte man natürlich noch verfeinern. Aber das sollte dann auch kein Problem mehr sein.
Gruß Ahmed
- Als Antwort markiert Ahmed Martens Mittwoch, 20. Mai 2015 18:01
Alle Antworten
-
Hallo Ahmed,
Möchtest Du mehrere Outlook-Attachments zu den Ressourcen der Projektmappe hinzufügen?
Gruß,
DimitarBitte haben Sie Verständnis dafür, dass im Rahmen dieses Forums, welches auf dem Community-Prinzip „IT-Pros helfen IT-Pros“ beruht, kein technischer Support geleistet werden kann oder sonst welche garantierten Maßnahmen seitens Microsoft zugesichert werden können.
-
Nein, ich habe eine Application und ich möchte jetzt per Drag&Drop die Attachments einer Outlook-Mail auf der Festplatte speichern.
Folgende Funktion habe ich inzwischen gefunden:
Private Sub lvwFile_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lvwFile.DragDrop Dim SubItem As ListViewItem Dim DTO = TryCast(e.Data, DataObject) Dim sPfad As String = My.Settings.Pfad_RoseSoft & "\MSeq_" & DataGridView1(2, DataGridView1.CurrentRow.Index).Value.ToString Dim sFileName As String = "" Dim iLastSort As SortOrder iLastSort = If(lvwFile.Sorting = SortOrder.None, SortOrder.Descending, lvwFile.Sorting) sPfad = sPfad & "\" & TabUnterverzeichnis.TabPages(TabUnterverzeichnis.SelectedIndex).Text FileSystemWatcher1.EnableRaisingEvents = False 'keine Reaktion auf Änderung Dim i As Long If DTO.GetDataPresent("FileDrop") Then For i = 0 To DTO.GetFileDropList.Count - 1 sFileName = System.IO.Path.GetFileName(DTO.GetFileDropList(i).ToString) SubItem = lvwFile.Items.Add(sFileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(DTO.GetFileDropList(i).ToString).LastWriteTime) System.IO.File.Move(DTO.GetFileDropList(i).ToString, sPfad & "\" & sFileName) Next ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then Dim objOL As New Outlook.Application Dim myobj As Outlook.MailItem For i = 1 To objOL.ActiveExplorer.Selection.Count myobj = objOL.ActiveExplorer.Selection.Item(i) Dim z As Int16 For z = 1 To myobj.Attachments.Count myobj.Attachments(z).SaveAsFile(IO.Path.Combine(sPfad, myobj.Attachments(z).DisplayName)) SubItem = lvwFile.Items.Add(myobj.Attachments(z).DisplayName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(IO.Path.Combine(sPfad, myobj.Attachments(z).DisplayName)).LastWriteTime) Next Next End If Dim blnSortDate As Boolean Dim iCol As Integer If lvwFile.Tag.ToString = "" Then iCol = 1 Else iCol = lvwFile.Tag End If 'iCol = CInt(If(myList.Tag = "", "1", myList.Tag)) blnSortDate = iCol With lvwFile .ListViewItemSorter = New comparebyFirstcolumn(iCol, blnSortDate, (iLastSort = SortOrder.Ascending)) .Sorting = iLastSort End With Call lvw_Design(lvwFile, Color.WhiteSmoke, DataGridView1.AlternatingRowsDefaultCellStyle.BackColor) FileSystemWatcher1.EnableRaisingEvents = True 'Reaktion auf Änderung End Sub
Allerdings kann ich jetzt nicht feststellen, ob es sich um eine EMail oder doch nur um die Attachments handelt.
Folgender Code soll zwar zwischen Mail (*.msg) oder Attachments unterscheiden. Das funktioniert aber leider nicht:
Dim objOL As New Outlook.Application Private Sub Label1_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Label1.DragOver If e.Data.GetDataPresent(DataFormats.FileDrop) Then 'handle a file dragged from Windows explorer e.Effect = DragDropEffects.Copy lblFormat.Text = "DragOver ... File drop" '__________________________________________________________________________________________________ ElseIf (e.Data.GetDataPresent("aryFileGroupDescriptor")) AndAlso (e.Data.GetDataPresent("FileContents")) Then 'handle an attachment dragged from Outlook e.Effect = DragDropEffects.Copy lblFormat.Text = "DragOver ... Attachment from Outlook" 'nicht getesteter Code Ende ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then 'handle a message dragged from Outlook e.Effect = DragDropEffects.Copy lblFormat.Text = "DragOver ... Outlook" '_________________________________________________________________________________________________ 'nicht getesteter Code Start: Else 'otherwise, do not handle e.Effect = DragDropEffects.None lblFormat.Text = "" End If End Sub
Die Anweisung
ElseIf (e.Data.GetDataPresent("aryFileGroupDescriptor")) AndAlso (e.Data.GetDataPresent("FileContents")) Then
wird nicht ausgewertet (Outlook 2010).
Wenn ich das noch hinbekomme, dann habe ich mein Problem gelöst.
Gruß Ahmed
- Bearbeitet Ahmed Martens Montag, 11. Mai 2015 05:53
-
Hallo Leute,
endlich habe ich die Lösung gefunden und es funktioniert einwandfrei.
Ich kann jetzt auch endlich alle seletkierten Anlagen auf einmal speichern.
Hier der Code:
If DTO.GetDataPresent("FileDrop") Then For i = 0 To DTO.GetFileDropList.Count - 1 sFileName = System.IO.Path.GetFileName(DTO.GetFileDropList(i).ToString) SubItem = lvwFile.Items.Add(sFileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(DTO.GetFileDropList(i).ToString).LastWriteTime) System.IO.File.Move(DTO.GetFileDropList(i).ToString, sPfad & "\" & sFileName) Next ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then Dim objOL As New Outlook.Application Dim myobj As Outlook.MailItem Dim objAtt As Outlook.AttachmentSelection = objOL.ActiveExplorer.attachmentselection If objAtt.Count = 0 Then 'Attachtments selectiert (0=Nein) For i = 1 To objOL.ActiveExplorer.Selection.Count myobj = objOL.ActiveExplorer.Selection.Item(i) sFileName = CleanFilename(myobj.Subject & ".msg") myobj.SaveAs(IO.Path.Combine(sPfad, sFileName)) SubItem = lvwFile.Items.Add(sFileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(IO.Path.Combine(sPfad, sFileName)).LastWriteTime) Next Else For i = 1 To objAtt.Count objAtt(i).SaveAsFile(IO.Path.Combine(sPfad, objAtt(i).FileName)) SubItem = lvwFile.Items.Add(objAtt(i).FileName) SubItem.SubItems.Add(My.Computer.FileSystem.GetFileInfo(IO.Path.Combine(sPfad, objAtt(i).FileName)).LastWriteTime) Next End If
Das könnte man natürlich noch verfeinern. Aber das sollte dann auch kein Problem mehr sein.
Gruß Ahmed
- Als Antwort markiert Ahmed Martens Mittwoch, 20. Mai 2015 18:01