public void Upload2(string AuthToken) { otAuth.AuthenticationToken = AuthToken; string name = "New Document111_" + System.DateTime.Now.Ticks; string FilePath = @C:\Users\TestUser\Desktop\HugeFileRollforward\5GBFilesZip.zip; int Offset = 0; int ChunkSize = 65536; byte[] Buffer = new byte[ChunkSize]; FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read); FileInfo fileInfo = new FileInfo(FilePath); long FileSize = new FileInfo(FilePath).Length; fs.Position = Offset; int BytesRead = 0; Node uploadedFile = null; try { while (Offset != FileSize) { BytesRead = fs.Read(Buffer, 0, ChunkSize); if (BytesRead != Buffer.Length) { ChunkSize = BytesRead; byte[] TrimmedBuffer = new byte[BytesRead]; Array.Copy(Buffer, TrimmedBuffer, BytesRead); Buffer = TrimmedBuffer; } try { fs.Seek(Offset, SeekOrigin.Begin); Attachment attachment = new Attachment(); attachment.Contents = Buffer; attachment.CreatedDate = fileInfo.CreationTime; attachment.FileName = fileInfo.Name; attachment.FileSize = Buffer.Length; attachment.ModifiedDate = fileInfo.LastWriteTime; if (uploadedFile == null) { uploadedFile = docManClient.CreateDocument(ref otAuth, 2000, name, "Uploaded from POC webservice", false, null, attachment); } else { uploadedFile = docManClient.CreateDocument(ref otAuth, uploadedFile.ID, name, "Uploaded from POC webservice", false, null, attachment); //I’m trying to update the content byte to the existing node. But I get error here that I cannot attach a file to a document container. It makes sense. But is there any other solution? } } catch { break; } // Offset is only updated AFTER a successful send of the bytes. Offset += BytesRead; // save the offset position for resume } } catch (Exception ex) { } finally { fs.Close(); } } |