Search code examples
c#alfrescodotcmis

Download from the Alfresco to a local folder


I was try download a file from the Alfresco to a local folder with DotCMIS, but the file always save blank, my code:

  ISession session = startSession();
  IObjectId id = session.CreateObjectId(fileId);

  Dictionary<String, Object> properties = new Dictionary<String, Object>();

  properties.Add(PropertyIds.Name, file);
  properties.Add(PropertyIds.ObjectId, fileId);
  properties.Add(PropertyIds.ObjectTypeId, "cmis:document,P:cm:titled");


  IDocument docx = session.GetObject(fileId) as IDocument;
  IContentStream content = docx.GetContentStream();
  Stream stream = content.Stream;
  string path = @"C:\Windows\Temp\" + docx.Name;

  using (stream = File.Create(path)) {}

Thanks everyone


Solution

  • Worked that way:

            BufferedStream document = (BufferedStream)content.Stream;
    
            string path = @"C:\Windows\Temp\" + docx.Name;
    
            using (FileStream stream = File.Create(path))
            {
                document.CopyTo(stream);
            }
    

    Thanks everyone