c# - Azure Function 找不到文档 openXML

标签 c# azure azure-functions

我是 Azure Functions 的新手,我正在尝试发现它的一些功能。

所以我创建了函数blob触发器,在project.json中添加了OpenXML sdk的引用

"frameworks": {
"net46":{
  "dependencies": {
    "WindowsAzure.Storage": "7.0.0" ,
    "Open-XML-SDK" : "2.7.2",
    "DocumentFormat.OpenXml" : "2.8.1"

在 run.csx 中我添加了下一个代码

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;
        }

问题是当我上传 .pptx 时,日志中有错误

Exception while executing function: Functions.BlobTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. DocumentFormat.OpenXml: Could not find document.

我使用 Microsoft Azure 存储资源管理器上传文件 .pptx,但我不明白为什么会出现错误。

最佳答案

您正在使用 following method :

public static PresentationDocument Open(
    string path,
    bool isEditable
)

它接受的第一个参数是path,但您可以在其中传递文件内容。它试图找到这个奇怪的文件路径并抛出异常。

尝试使用Stream overload .

关于c# - Azure Function 找不到文档 openXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50563103/

相关文章:

c# - 在 ASP.Net c# 中执行多个读取器

azure - 无法使用 terraform 在 cosmos db 中设置自动缩放

azure - 将Azure容器应用程序部署到Azure管道中的不同资源组

asp.net - 为什么每次推送新版本的 Azure Web 角色时,我的 machineKey 都会发生变化?

r - 用于运行 R 脚本的 Azure ML 与 Azure 函数

c# - 在 WCF 中使用属性

c# - 如何在 MediaPlayer 中播放来自 SpeechSynthesizer 的 wav 文件

visual-studio - Azure功能单独调试和部署

c# - 如何将多个操作数应用于单个运算符?

c# - 在 Azure Function 中访问 VSTS 构建服务器版本