如何使用 vb.net 将文件上传到 MS 一个驱动器? [英] How to upload files to MS one drive using vb.net?

查看:24
本文介绍了如何使用 vb.net 将文件上传到 MS 一个驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次做这个项目,我的项目经理给了我时间研究如何去做.我是google过来的,有些代码太复杂了,有没有简单的方法怎么做?或者我猜可能不会太复杂.

It's my first time to do the project and my project manager give me time to research how to do it. I came from google and some codes are too complicated, is there a simple way how to do it? or maybe not too complicated I guess.

推荐答案

''' <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" & "\\" & "Software\Microsoft\Windows\CurrentVersion\SkyDrive"
    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), "Microsoft\OneDrive\OneDrive.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

这篇关于如何使用 vb.net 将文件上传到 MS 一个驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆