Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 3.0 从.ppt转换powerpoint文件->。使用c#.net 2008使用比特流进行pptx_C# 3.0_Powerpoint 2007 - Fatal编程技术网

C# 3.0 从.ppt转换powerpoint文件->。使用c#.net 2008使用比特流进行pptx

C# 3.0 从.ppt转换powerpoint文件->。使用c#.net 2008使用比特流进行pptx,c#-3.0,powerpoint-2007,C# 3.0,Powerpoint 2007,我正在尝试通过使用linq从sql数据库中使用二进制数据创建并打开powerpoint A.首先我将其读入字节数组,然后创建.ppt文件。 public bool createPresentation(string fileName, byte[] powerPoint) { DirectoryInfo di = new DirectoryInfo(downloadPath); if (!di.Exists) di.Create()

我正在尝试通过使用linq从sql数据库中使用二进制数据创建并打开powerpoint

A.首先我将其读入字节数组,然后创建.ppt文件。

public bool createPresentation(string fileName, byte[] powerPoint)
    {
        DirectoryInfo di = new DirectoryInfo(downloadPath);
        if (!di.Exists)
            di.Create();

        fileName = string.Concat(downloadPath, fileName,".PPT");
        //Define a new instance of FileStream
        FileStream powerpointStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
       powerpointStream.Write(powerPoint, 0, powerPoint.Count());
       powerpointStream.Close();

        return True; 
    }
    public byte[] convertToBinary(string source)
    {
        byte[] binary = File.ReadAllBytes(source);
        return binary;
    }
B.然后我尝试打开.ppt文件并将其另存为.pptx文件

public bool convertPPTtoPPTX(string path)
    {
        string source = path;
        string destination = path.Replace("PPT", "PPTX");

        DirectoryInfo di = new DirectoryInfo(downloadPathPPTX);
        if (!di.Exists)
            di.Create();

        PowerPoint.Application app = new PowerPoint.Application();//Line Y

        PowerPoint.Presentation pptx = app.Presentations.Open(source, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse);//Line Z
        pptx.SaveAs(destination, PowerPoint.PpSaveAsFileType.ppSaveAsDefault);
        pptx.Close();
        app.Quit();

       return true;
    }
C。最后,我尝试将.pptx文件读入字节数组,以便通过linq更新数据库。

public bool createPresentation(string fileName, byte[] powerPoint)
    {
        DirectoryInfo di = new DirectoryInfo(downloadPath);
        if (!di.Exists)
            di.Create();

        fileName = string.Concat(downloadPath, fileName,".PPT");
        //Define a new instance of FileStream
        FileStream powerpointStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
       powerpointStream.Write(powerPoint, 0, powerPoint.Count());
       powerpointStream.Close();

        return True; 
    }
    public byte[] convertToBinary(string source)
    {
        byte[] binary = File.ReadAllBytes(source);
        return binary;
    }
E。这是我通过linq sql获取二进制数据的方式

public List<Template> getPPTFileBiniary(int ID)
    {
        var ppt = from p in db.paPresentationTemplates
                  where p.ID==ID
                  select new Template { pptFile = p.PPTFile.ToArray() };

        return ppt.ToList();
    }
关于这件事,我有几个问题

  • 对于下面的字节流,我抛出了一个错误,声明:“PowerPoint无法打开该文件。”。 字节数据:“0x00000000000000” 为什么呢
  • 对于某些运行时实例,从部分B第Y行再次引发以下异常。 “由于以下错误,从IClassFactory创建CLSID为{91493441-5A91-11CF-8700-00AA0060263B}的COM组件实例失败:80010108”。但当我使用F11键进行调试时,不会引发此异常。有人能解释一下吗
  • 此外,在调用part B的某些情况下,当powerpoint甚至没有在我的taskmanager进程中运行时,会引发一个异常,表明“powerpoint文件正在被其他程序/应用程序使用”
  • 请帮助我克服这些障碍。 谢谢
    Yasindu。

    我找到了问题第一部分的原因以及第二个问题的解决方案

    Q1:
    发生这种情况是因为ppt文件的保存位流表示已损坏的文件。因此,一旦创建,它就无法打开

    问题2: 当我总是试图在循环中创建一个新的应用程序实例时,就会发生错误。 所以,, 1.我在类的顶部创建了实例,并禁用了app.Quit()方法调用。 2.关闭power point对象后,我通过将其等于Null来确保该对象已被销毁。(pptx=Null;)


    Q3对我来说仍然是一个疑问,如果有任何专家帮助,我将不胜感激。

    我找到了问题第一部分的原因以及第二个问题的解决方案

    Q1:
    发生这种情况是因为ppt文件的保存位流表示已损坏的文件。因此,一旦创建,它就无法打开

    问题2: 当我总是试图在循环中创建一个新的应用程序实例时,就会发生错误。 所以,, 1.我在类的顶部创建了实例,并禁用了app.Quit()方法调用。 2.关闭power point对象后,我通过将其等于Null来确保该对象已被销毁。(pptx=Null;)

    Q3对我来说仍然是一个疑问,如果有任何专业知识的帮助,我将不胜感激