Terrasoft.File.Content.FileContentStream.get_Length()

Hi everybody. We'd applied a code from here https://academy.creatio.com/docs/developer/back_end_development/api_for… (Get file content part). The code is the following:

	byte[] data;
	Guid recordId = entities[0].GetTypedColumnValue<Guid>("Id");
	var fileLocator = new EntityFileLocator("KnowledgeBaseFile", recordId);
	IFile file = userConnection.GetFile(fileLocator);
	// Read the contents of the file in the content byte array. Remember to free the stream object by utilizing using! 
	using (Stream stream = file.Read()) {
	   data = stream.ReadAllBytes();
	}
 
	string s1 = Encoding.GetEncoding("Windows-1250").GetString(data);

actually it is the same as in the creatio example on the page:

 

byte[] content;
Guid recordId = Guid.NewGuid();
var fileLocator = new EntityFileLocator("ActivityFile", recordId);
IFile file = connection.GetFile(fileLocator);
 
// Read the contents of the file in the content byte array. Remember to free the stream object by utilizing using! 
using (Stream stream = file.Read()) {
   content = stream.ReadAllBytes();
}

unfortunately if fails with the following:

 

System.NotSupportedException: Specified method is not supported. at Terrasoft.File.Content.FileContentStream.get_Length() at Terrasoft.Common.StreamUtilities.ReadAllBytes(Stream source) at Terrasoft.Core.Process.EonFileProceedingCustom10MethodsWrapper.ScriptTask1Execute(ProcessExecutingContext context) at Terrasoft.Core.Process.ProcessFlowElement.ExecuteItem(ProcessExecutingContext context) at Terrasoft.Core.Process.ProcessFlowElement.Execute(ProcessExecutingContext context)

 

honestly I don't understand the problem because it occurs in the core method :( Does anybody have a solution please?

 

8.0.6 sales team

 

Like 0

Like

1 comments

Hello,

You using ReadAllBytes(), however, even the article you provided used another method ReadToEnd().

Please change the method and see if the problem is still present.

 

using Terrasoft.Common;
 
var content = new byte[]();
Guid recordId = Guid.NewGuid();
 
/* Create a file locator for the new file. */
var fileLocator = new EntityFileLocator("ActivityFile", recordId);
IFile file = UserConnection.GetFile(fileLocator);
 
/* Read the contents of the file in the content byte array. Remember to free the stream object by utilizing using! */
using (Stream stream = file.Read()) {
   content = stream.ReadToEnd();
}

 

Show all comments