Hi All,
I writed plugin to get uploaded excel attachment to Annotation record. In plugin I am saving excel attahcment files "c:/temp" folder so i can successfully read excel files. Here is code:
private static string SaveFile(string fileName, string noteBody)
{
string outputFileName = @"C:\temp\" + fileName;
if (!string.IsNullOrEmpty(noteBody))
{
// Download the attachment in the current execution folder.
byte[] fileContent = Convert.FromBase64String(noteBody);
System.IO.File.WriteAllBytes(outputFileName, fileContent);
}
else
{
throw new InvalidPluginExecutionException("File content is empty or cannot be retrieved");
}
return outputFileName;
}
Now i want to read excel file without saving it. I tried this but i am getting "Files contains corrupted data". Here is my code:
byte[] file = new UTF8Encoding(true).
GetBytes(Convert.ToString(entity.Attributes["documentbody"]));
using (var templateStream = new MemoryStream())
{
templateStream.Write(file, 0, file.Length);
using (var excelDoc = SpreadsheetDocument.Open(templateStream, true))
{
////Getting error
}
templateStream.Position = 0;
var result = templateStream.ToArray();
templateStream.Flush();
}
What i must supposed to do to read excel file from byte array without saving it? Any idea?