使用Sharpbox上传文件时出错

时间:2014-02-16 15:19:54

标签: vb.net cloud sync dropbox-api sharpbox

我正在尝试将文件上传到sharpbox。

我的应用已注册为可以访问Dropbox帐户中任何文件的应用。它创建没有问题的文件夹。但是当它试图上传文件时,我得到以下异常:

Exception of type 'AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException' was thrown.

我使用以下代码:

    Dim accessToken As ICloudStorageAccessToken
    Dim dropBoxStorage As New CloudStorage()

    If IO.Directory.Exists(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud") Then
        Using fs = File.Open(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SharpDropBox.token", FileMode.Open, FileAccess.Read, FileShare.None)
            accessToken = dropBoxStorage.DeserializeSecurityToken(fs)
        End Using
        Using reader As New ResourceReader(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SN.bsn")
            For Each i As DictionaryEntry In reader
                unpass.Items.Add(i.Value)
            Next
        End Using
    Else
        IO.Directory.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud")
        IO.File.WriteAllBytes(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SharpDropBox.token", My.Resources.SharpDropBox)
        Using writer As New ResourceWriter(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SN.bsn")
            writer.AddResource("1", mystring)
            writer.AddResource("2", mystring1)
            writer.Close()
        End Using
        Using reader As New ResourceReader(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SN.bsn")
            For Each i As DictionaryEntry In reader
                unpass.Items.Add(i.Value)
            Next
        End Using


        Using fs = File.Open(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud/SharpDropBox.token", FileMode.Open, FileAccess.Read, FileShare.None)
            accessToken = dropBoxStorage.DeserializeSecurityToken(fs)
        End Using

        firsttime = True
    End If


    Dim dropBixConfig = CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox)
    Dim storageToken = dropBoxStorage.Open(dropBixConfig, accessToken)

    If firsttime = True Then
        Try
            dropBoxStorage.GetFolder("/My App Files/" + mystring)
            IO.Directory.Delete(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/cloud")
            Call Me.errornew()
        Catch ex As Exception
            Dim remoteDirName As String = "/My App Files/" + mystring1
            Dim targetDir As String = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
            Try
                dropBoxStorage.CreateFolder(remoteDirName)
                dropBoxStorage.CreateFolder(remoteDirName + "sysdata")
                dropBoxStorage.Open(dropBoxConfig, accessToken)
                IO.File.WriteAllText(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/sysdata.brsi", pass)
                dropBoxStorage.GetFolder("/My App Files/" + mystring1 + "sysdata")
                dropBoxStorage.UploadFile(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/myfile.txt", "/My App Files/" + mystring + "sysdata")
                IO.File.Delete(My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "/sysdata.brsi")
             call dosomethingafterwards()
            Catch ex1 As Exception
                MsgBox("An error was occured while My App tried to download your files, and it will now switch to offline mode. Try to connect the internet, and then restart My App. We're sorry.")
                Call new1()
            End Try
        End Try
        dropBoxStorage.Close()

    Else
        Dim remoteDirName As String = "/My App Files/" + mystring
        Dim targetDir As String = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
        Try
            Dim remoteDir = dropBoxStorage.GetFolder(remoteDirName)
            DownloadFolder(dropBoxStorage, remoteDir, targetDir, remoteDirName)
        Catch ex123 As Exception

            MsgBox("An error was occured while My App tried to download your files, and it will now switch to offline mode. Try to connect the internet, and then restart My App. We're sorry.")
            Call dosomethingafterwards()

        End Try


        dropBoxStorage.Close()
    End If

我的代码有什么问题,我该如何解决?

0 个答案:

没有答案