AnsweredAssumed Answered

Getting error while uploading file to Alfresco using API in .Net C#

Question asked by naveenpz on Mar 2, 2017



I am using the following code to upload files to Alfresco server. 


private static HttpResponseMessage AlfrescoUploadFile(AlfrescoInfo alfresco, HttpClient client, byte[] fileData, string fileName, string orginalFileName)
HttpResponseMessage fileUploadResponse = new HttpResponseMessage();
HttpContent filenameContent = new StringContent(fileName);
HttpContent destinationContent = new StringContent(alfresco.TagSearch[0].nodeRef);
HttpContent fileContent = new ByteArrayContent(fileData);

using (var content = new MultipartFormDataContent())
//Add Headers
filenameContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "filename" };
destinationContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "destination" };
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "filedata", FileName = orginalFileName };

fileUploadResponse = client.PostAsync(alfresco.URL + "/upload?alf_ticket=" +, content).Result;

catch (Exception ex)
new ExceptionService().LogException(ex);
return fileUploadResponse;


While uploading files using the above code, i am getting errors/inner exceptions like 

  1. One or more errors occurred.
  2. Error while copying content to a stream
  3. An existing connection was forcibly closed by the remote host
  4. Value cannot be null. Parameter name: content
  5. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.


This error occures rarely, not in all senarios.


Can anyone help to resolve this?