unable to copy the file from box to sharepoint
I am able to get the bytes from box file. But when iam uploading the file in the sharepoint library using the bytes, i am able to write, but when iam opening the file it is corrupted. Any body let me know anything wrong with the below c# code for getting bytes of a file from box site:
string url = "https://api.box.com/2.0/files/" + fileid + "/content";
Uri Site = new Uri(url);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Site);
req.Method = "GET";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Authorization", "Bearer " + acessToken);
req.Accept = "application/json;odata=verbose";
req.Headers.Add("binaryStringResponseBody", "true");
WebResponse webResponse = req.GetResponse();
using (Stream responseStream = webResponse.GetResponseStream())
{
using (MemoryStream ms = new MemoryStream())
{
int count = 0;
do
{
count = responseStream.Read(buffer, 0, buffer.Length);
ms.Write(buffer, 0, count);
} while (count != 0);
buffer = ms.ToArray();
}
}
-
I would recommend using our .NET SDK to implement this. Here is the method from our .NET SDK to download a file.
Stream stream = await client.FilesManager.DownloadStreamAsync(fileId);
Please sign in to leave a comment.
Comments
1 comment