I am trying to upload a file to sharpbox.
my app is registered as an app that can access to any of the files in my Dropbox account. It creates folders with no problem. But when It's trying to upload a file, I get the following exception:
Exception of type 'AppLimit.CloudComputing.SharpBox.Exceptions.SharpBoxException' was thrown.
I use the following code:
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
What is wrong in my code, and how can I fix it?