Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
for (int i = 0; i < ltTemplateIndex.Count; i++)
{
    if (i == 0)
    {
        ppMergedPres = ppSet.Open(Path.GetTempPath() + @"\template" + i + ".ppt", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
        ppMergedSlides = ppMergedPres.Slides;
    }
    else
    {
        ppPres = ppSet.Open(Path.GetTempPath() + @"\template" + i + ".ppt", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
        if (ltTemplateIndex.Count > 1)
        {
            try
            {
                ppMergedSlides.InsertFromFile(Path.GetTempPath() + @"\template" + i + ".ppt", ppMergedSlides.Count, 1, ppPres.Slides.Count);
            }
            catch (Exception ex) { }
            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();
Posted
Updated 26-Nov-14 19:02pm
v2
Comments
[no name] 26-Nov-14 2:01am    
What do u get in ltTemplateIndex.Count ?
Amresh Bahadur Singh 26-Nov-14 2:05am    
is a List ...
public static List<int> ltTemplateIndex = new List<int>();
Amresh Bahadur Singh 26-Nov-14 2:06am    
ltTemplateIndex.Count is Maximum is 11
I think you need to close the stream after use. ppSet.Open() is there. You should write ppSet.Close() and Dispose() to dispose the resources so that they can be reused again.

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)
C#
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();
                } 
            }
        }
    }  // Resources will be released here
}
 
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();
 
Share this answer
 
Please use this Code and focus bold area .

C#
ppMergedPres.SaveAs((System.Web.Hosting.HostingEnvironment.MapPath("~/Results/" + pptFileName)), PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, MsoTriState.msoFalse);
            ppMergedPres.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900