如何使用 vb.net 将文件上传到MS One驱动器



这是我第一次做这个项目,我的项目经理给我时间研究如何做。我来自谷歌,有些代码太复杂了,有没有简单的方法可以做到这一点?或者我猜可能不太复杂。

''' <summary>
''' Uploads a file to  Microsoft OneDrive.
''' </summary>
''' <param name="FilePath">Path of a file to upload from.</param>
''' <exception cref="KeyNotFoundException">The registry key of MS OneDrive is not found.</exception>
''' <returns>The path of file inside MS OneDrive folder.</returns>
''' <remarks></remarks>
Function UploadToMSOneDrive(FilePath As String) As String
    Const keyName As String = "HKEY_CURRENT_USER" & "\" & "SoftwareMicrosoftWindowsCurrentVersionSkyDrive"
    Const DefaultKey As String = "OMG Teh ReGiStRy DOesn''''t E.x;I's|T!!!"
    Dim OneDrivePath As String = DirectCast(Microsoft.Win32.Registry.GetValue(keyName, "UserFolder", DefaultKey), String)
    Dim MSOneDriveProgram As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MicrosoftOneDriveOneDrive.exe")
    Dim Destination As String = IO.Path.Combine(If(OneDrivePath = DefaultKey, OneDrivePath, ThrowKeyNotFoundException("Is MS OneDrive not installed?")), IO.Path.GetFileName(FilePath))
    My.Computer.FileSystem.CopyFile(FilePath, Destination)
    Process.Start(MSOneDriveProgram)
    Return Destination
End Function
Friend Function ThrowKeyNotFoundException(Message As String) As Type
    Throw New KeyNotFoundException(Message)
    Return GetType(Void) ' This will not be reached
End Function

相关内容

最新更新