You could try to add a using statement when opening the file.
This will automatically Close and Dispose the object (if there is an IDisposable interface implemented)
for (int i = 0; i < ltTemplateIndex.Count; i++)
{
string fileName = Path.Combine( Path.GetTempPath(),
String.Format(@"template{0}.ppt";
using (var ppTemp = ppSet.Open(fileName, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse))
{
if (i == 0)
{
ppMergedPres = ppTemp;
ppMergedSlides = ppMergedPres.Slides;
}
else
{
ppPres = ppTemp;
if (ltTemplateIndex.Count > 1)
{
try
{
ppMergedSlides.InsertFromFile(fileName, ppMergedSlides.Count, 1, ppPres.Slides.Count);
}
catch (Exception ex) { }
finally
{
if (ppPres != null)
ppPres.Close();
}
}
}
}
}
string directoryPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Results");
if (!Directory.Exists(directoryPath))
Directory.CreateDirectory(directoryPath);
ppMergedPres.SaveAs(
Path.Combine(directoryPath, pptFileName),
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
MsoTriState.msoFalse);
ppMergedPres.Close();