【问题标题】:VB.NET - How to Drag a File From Outlook 2010 to My Form?VB.NET - 如何将文件从 Outlook 2010 拖到我的表单中?
【发布时间】:2013-03-28 00:57:57
【问题描述】:

我正在开发一个应用程序来读取 XML 文件、获取其数据并填充一些字段。所以,我实现了两种获取文件的方法:通过命令按钮和拖放表单事件。如果我使用存储在计算机文件夹中的文件,一切正常。我可以拖动文件,光标将其外观更改为复制效果等。但是,当我尝试将文件作为 Outlook 的附件拖动时(我的版本是 2010),我看到光标呈现禁止效果,并且文件未被读取。

请看下面我所做的实现,它仅适用于存储在我计算机文件夹中的文件。我想知道我还需要实现什么才能允许从 Outlook 中拖动文件。

提前谢谢你。

    Private Sub FrmJIG_DragDrop(sender As Object, e As DragEventArgs) _
    Handles Me.DragDrop
    Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
    Dim filestype() As String

    filestype = e.Data.GetData(DataFormats.FileDrop)
    Dim sReader As New StreamReader(filestype(0))

    'get the filename from the file without the path
    Dim file_name As String = Path.GetFileName(filestype(0))

    'check the extension of the file
    If Path.GetExtension(filestype(0)).ToLower() = ".xml" Then
        'Read the xml file
        For Each path In files
            ReadXMLFile(path)
        Next
    Else

        'warning about the file type
        MessageBox.Show("Only XML files are supported!", "Warning!", _
MessageBoxButtons.OK, _
    MessageBoxIcon.Warning)
    End If
End Sub

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

【问题讨论】:

  • 请尝试检查e.Data.GetDataPresent("FileGroupDescriptor")
  • 你好爱德华多。感谢你的回复。在上面的代码中应该如何实现?
  • 添加了修改代码的aswer

标签: vb.net drag-and-drop outlook-2010


【解决方案1】:

请尝试

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) or e.Data.GetDataPresent("FileGroupDescriptor") Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

【讨论】:

  • 你好爱德华多。非常感谢!我今晚试试。
  • 嗨,爱德华多。您的提示可以很好地更改光标行为。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-13
  • 2015-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
相关资源
最近更新 更多