我正在尝试添加拖放功能到我的表单,以便我可以从电子邮件中拖动附件,它将保存附件。
我得到一个错误,说所需的权限不是由客户端持有。我想绕过这个问题。
下面是我的代码:
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发布于 2015-07-14 14:19:05
您肯定没有写入c:\的权限。
我建议使用My.Computer.FileSystem.SpecialDirectories对象写到你的桌面或其他地方:
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
https://stackoverflow.com/questions/31379260
复制相似问题