首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将电子邮件附件拖放到C盘

将电子邮件附件拖放到C盘
EN

Stack Overflow用户
提问于 2015-07-13 17:02:04
回答 1查看 527关注 0票数 0

我正在尝试添加拖放功能到我的表单,以便我可以从电子邮件中拖动附件,它将保存附件。

我得到一个错误,说所需的权限不是由客户端持有。我想绕过这个问题。

下面是我的代码:

代码语言:javascript
复制
If e.Data.GetDataPresent("FileGroupDescriptor") Then

Dim theStream As Stream = DirectCast(e.Data.GetData("FileGroupDescriptor"), Stream)
Dim fileGroupDescriptor As Byte() = New Byte(511) {}
theStream.Read(fileGroupDescriptor, 0, 512)

Dim fileName As New StringBuilder("")
Dim i As Integer = 76
While fileGroupDescriptor(i) <> 0
    fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
    i += 1
End While
theStream.Close()

Dim theFile As String = "c:\" + fileName.ToString() 'change the c:\ to any path you want

Dim ms As MemoryStream = DirectCast(e.Data.GetData("FileContents", True), MemoryStream)
Dim fileBytes As Byte() = New Byte(ms.Length - 1) {}
ms.Position = 0
ms.Read(fileBytes, 0, CInt(ms.Length))

Dim fs As New FileStream(theFile, FileMode.OpenOrCreate)
fs.Write(fileBytes, 0, CInt(fileBytes.Length))
fs.Close()
End If
EN

回答 1

Stack Overflow用户

发布于 2015-07-14 14:19:05

您肯定没有写入c:\的权限。

我建议使用My.Computer.FileSystem.SpecialDirectories对象写到你的桌面或其他地方:

代码语言:javascript
复制
   Dim theFile As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, filename.ToString)

查看本文,了解您可以使用的所有选项:https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.specialdirectories.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31379260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档