We are using Box.V2.Sdk to upload files to box.com using the following code
Function UploadToBox(ByVal attachedFilename As String, ByVal stream As System.IO.Stream) As Boolean
Dim clientID As String
Dim clientSecret As String
Dim oldRefreshToken As String
Dim newToken As BoxApi.V2.Authentication.OAuth2.OAuthToken
clientID = "your client id"
clientSecret = "you client secret"
Dim tokenProvider As New TokenProvider(clientID, clientSecret)
'''' Reading Refresh token from the file
Dim streamReader As StreamReader
streamReader = System.IO.File.OpenText(Server.MapPath("~\\Box\\BoxApiRefreshToken.txt"))
oldRefreshToken = streamReader.ReadToEnd()
streamReader.Close()
newToken = tokenProvider.RefreshAccessToken(oldRefreshToken)
Dim boxManager As New BoxManager(newToken.AccessToken)
'''' Writing the new Refresh token to the file
Dim streamWriter As New StreamWriter(Server.MapPath("~\\Box\\BoxApiRefreshToken.txt"))
streamWriter.Write(newToken.RefreshToken)
streamWriter.Close()
Dim rootFolder As Folder
rootFolder = boxManager.GetFolder(Folder.Root)
boxManager.CreateFile(rootFolder, attachedFilename, ConvertStreamToByteArray(stream))
Return True
End Function
mentioned here http://www.codeproject.com/Tips/769414/Uploading-files-using-Box-API
The UploadToBox method is in a loop and called for every file we need to upload. However, after few uploads, we are getting the error
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Intuitively it appears that the connection to box is getting closed. But from the code above, we dont know which part is trying to create the connection, and if its closed then create a new one. Its fairly easy with c# SqlConnection to check if connection is open or closed.
Please suggest your thoughts.