I am new in Azure Functions and i am try to discover some features of it.
So i created function blob trigger, added references of OpenXML sdk in project.json
"frameworks": {
"net46":{
"dependencies": {
"WindowsAzure.Storage": "7.0.0" ,
"Open-XML-SDK" : "2.7.2",
"DocumentFormat.OpenXml" : "2.8.1"
And in run.csx i added next code
using System;
using System.IO;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
public static void Run (Stream myBlob, string name, TraceWriter log)
{
// *While we upload a blob, function start to execute*
StreamReader reader = new StreamReader(myBlob);
string S = reader.ReadToEnd();
int numberofSlides = CountSlides(S);
log.Info($"Number of slides = {numberofSlides}");
}
// *here, using XML sdk we open our presentation without using Office*
public static int CountSlides(string presentationFile)
{
using (PresentationDocument presentationDocument =PresentationDocument.Open(presentationFile, false))
{
return CountSlides(presentationDocument);
}
}
public static int CountSlides(PresentationDocument presentationDocument)
{
if (presentationDocument == null)
{
throw new ArgumentNullException("presentationDocument");
}
int slidesCount = 0;
PresentationPart presentationPart = presentationDocument.PresentationPart;
if (presentationPart != null)
{
slidesCount = presentationPart.SlideParts.Count();
}
return slidesCount;
}
The problem is while i upload a .pptx , i have error in log
Exception while executing function: Functions.BlobTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. DocumentFormat.OpenXml: Could not find document.
I upload a file .pptx using Microsoft Azure Storage Explorer and I can not understand why i have an error.