Hi I'm trying to create and open a powerpoint by using binary data from a sql database by using linq.
A. First I'm reading it into a byte array and then creating the .ppt file.
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;
}
B. Then I'm trying to open the .ppt file and save it as a .pptx file
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. Finally I'm trying to read the .pptx file into a byte array inorder to update the db through linq.
public byte[] convertToBinary(string source)
{
byte[] binary = File.ReadAllBytes(source);
return binary;
}
E. This is how i obtain the binary data through 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();
}
F. Template class used in E
class Template
{
public int ID { get; set; }
public string FileName { get; set; }
public Byte[] pptFile { get; set; }
public Template()
{
}
}
I've got several issues regarding this.
- For the following byte stream, I get a error thrown, stating: "PowerPoint could not open the file." from part B Line Z. byte data: "0x00000000000000000000" Why is that?
- For some runtime instances the following exception is thrown again from Part B Line Y. "Creating an instance of the COM component with CLSID {91493441-5A91-11CF-8700-00AA0060263B} from the IClassFactory failed due to the following error: 80010108". But when I debug using F11 key, this exception is not thrown. Can someone please explain this?
- Also for some instances when calling part B, an exception is thrown which states "the powerpoint file is being used by another program/application." When powerpoint is not even running in my taskmanager processes.
Please help me to overcome these barriers. Thanks, Yasindu.