2016-05-30 52 views
-1

私はこのプロジェクトを初めてやりました。私のプロジェクトマネージャーは、それをやる方法を研究する時間を私に与えてくれました。私はGoogleから来て、いくつかのコードは複雑すぎる、それを行うには簡単な方法がありますか?あまりにも複雑すぎるかもしれないと思います。vb.netを使ってMSのドライブにファイルをアップロードするには?

+1

何かをコードしようとしましたか?もしそうなら、それを私たちと分かち合うことができますか? – ChicagoMike

+0

私はそうではありませんでした。私はvb.netを使って簡単なサンプルコードを探しています。お手伝いをいただければ幸いです。 – Kiro

答えて

0
''' <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 
関連する問題