2
votes

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.

1
you might be missing anything that's why you getting an error while uploading file refer to this link for step by step guide and see if it helps. docs.microsoft.com/en-us/azure/…Zahid Faroq

1 Answers

1
votes

You are using the following method:

public static PresentationDocument Open(
    string path,
    bool isEditable
)

The first parameter it accepts is path but you pass the file contents in there. It tries to find this weird file path and throws exception.

Try using the Stream overload.