2015-07-13 85 views
0

我想添加拖放功能到我的窗體,這樣我就可以從電子郵件拖動附件,它會保存附件。電子郵件附件拖放到C驅動器

我收到一個錯誤,說客戶端沒有要求的權限。我想解決這個問題。

這裏是我的代碼:

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 
+0

它聽起來就像你沒有權限或它沒有正確設置保存到Windows下的該目錄。看看這個鏈接是否幫助你:** http://answers.microsoft.com/en-us/windows/forum/windows_vista-security/error-0x80070522-a-required-privilege-is-not-held/78cc11ec- c543-418d-9183-131318e9db8a?AUTH = 1 **。此外,錯誤來自哪裏?如果你設置了一個斷點並且跳過,那麼它應該在導致問題的線上斷開。我最好的猜測是:'fs.Write(fileBytes,0,CInt(fileBytes.Length))'或'Dim fs As New FileStream(theFile,FileMode.OpenOrCreate)' – Codexer

回答