| |
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="Merge-Presentations.aspx.cs" Inherits="Merge_Presentations.Merge_Presentations" Title="Merging Presentations" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="41" valign="top">
<img src="/Common/images/heading_lft.jpg" width="19" height="41" /></td>
<td width="100%" class="demos-heading-bg">
<h2 class="demos-heading-bg">
Presentations Merging Demo - Aspose.Slides for .NET</h2>
</td>
<td valign="top">
<img src="/Common/images/heading_rt.jpg" width="19" height="41" /></td>
</tr>
</table>
<p class="componentDescriptionTxt">
The sample demo merges two presentations by using <strong> Slides Cloning</strong> feature of Aspose.Slides for .NET. Click <strong>Browse</strong> buttons to select the
two PowerPoint 97-2003 format presentations (PPT) and then click <strong>Download Merged Presentation</strong> button to download the locked
Presentation created by merging the provided presentations.
</p>
<p>
<asp:Label ID="lblErr" runat="server" Font-Bold="True" ForeColor="Red" Text="Label"
Visible="False"></asp:Label> </p>
<asp:Label ID="Label1" runat="server" Text="Enter First Presentation"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Label ID="Label2" runat="server" Text="Enter Second Presentation"></asp:Label>
<asp:FileUpload ID="FileUpload2" runat="server" /><br />
<br />
<asp:Button ID="btn_Download" runat="server" OnClick="btn_Download_Click" Text="Dwonload Merged Presentation" />
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aspose.Slides;
using Aspose.Slides.Export;
namespace Merge_Presentations
{
public partial class Merge_Presentations : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Download_Click(object sender, EventArgs e)
{
if (this.FileUpload1.HasFile && this.FileUpload2.HasFile)
{
this.lblErr.Visible = false;
try
{
//Upload first presentation
string strFile1 = this.FileUpload1.FileName.Substring(0, this.FileUpload1.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") + ".ppt";
this.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile1));
//Upload second presentation
string strFile2 = this.FileUpload2.FileName.Substring(0, this.FileUpload2.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") + ".ppt";
this.FileUpload2.PostedFile.SaveAs(Server.MapPath(strFile2));
//Load the uploaded presentations
Presentation srcPres1 = new Presentation(Server.MapPath(strFile1));
Presentation srcPres2 = new Presentation(Server.MapPath(strFile2));
//Create a new presentation
Presentation targetPres1 = new Presentation();
//Clone first presentation with the newly created presentation
Presentation targetPres2 = getClonedPres(srcPres1, targetPres1);
//Clone the second presentation with the resulting presentation
Presentation mergedPresentation = getClonedPres(srcPres2, targetPres2);
//Remove the first default slide of the merged presentation
mergedPresentation.Slides.Remove(mergedPresentation.GetSlideByPosition(1));
//Save the merged presentation to the response stream
mergedPresentation.Save("MergedPres.ppt", SaveFormat.Ppt, Response, false);
Response.End();
}
catch (Exception ex)
{
this.lblErr.Visible = true;
this.lblErr.Text = ex.Message;
}
}
}
public Presentation getClonedPres(Presentation srcPres, Presentation targetPres)
{
SortedList sl = new SortedList();
for (int i = 1; i <= srcPres.Slides.LastSlidePosition; i++)
{
Slide srcSlide = srcPres.GetSlideByPosition(i);
srcPres.CloneSlide(srcPres.GetSlideByPosition(i), targetPres.Slides.LastSlidePosition + 1, targetPres, sl);
Slide targetSlide = null;
if (srcSlide.Notes != null)
{
targetSlide = targetPres.GetSlideByPosition(targetPres.Slides.LastSlidePosition);
targetSlide.AddNotes();
for (int j = 0; j < srcSlide.Notes.Paragraphs.Count; j++)
targetSlide.Notes.Paragraphs.Add(new Paragraph(srcSlide.Notes.Paragraphs[j]));
targetSlide.Notes.Paragraphs.RemoveAt(0);
}
}
return targetPres;
}
}
}
|
|
|
|