| |
| 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
33
34
35
36
37
38
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="Lock-Presentation.aspx.cs" Inherits="Lock_Presentation.Lock_Presentation" Title="Presentation Locking - Aspose.Slides" %>
<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">
Presentation Locking / Unlocking 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 makes use of locking feature provided by Aspose.Slides for .NET. Click <strong>Browse</strong> button to select the
PowerPoint 97-2003 format presentation (PPT) and then click <strong>Download Locked Presentation</strong> button to download the locked
Presentation. Once a presentation is locked, it can only be unlocked by Aspose.Slides for .NET as MS PowerPoint can not lock / unlock a
Presentation. Press <strong>Download Unlocked Presentation</strong> button to unlock a presentation after browsing the locked presentation.
</p>
Enter your PowerPoint Presentation (PPT)<asp:FileUpload ID="FileUpload1" runat="server" Width="389px">
</asp:FileUpload><br />
<asp:Label ID="Label1" runat="server" ForeColor="Red" Width="401px" Font-Bold="True"></asp:Label>
<asp:Button ID="btn_Download" runat="server" OnClick="btn_Download_Click" Text="Download Locked Presentation" /> <asp:Button
ID="btn_Unlock" runat="server" OnClick="btn_Unlock_Click" Text="Download Unlocked Presentation"
Width="266px" /><br />
</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;
namespace Lock_Presentation
{
public partial class Lock_Presentation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Download_Click(object sender, EventArgs e)
{
this.Label1.Visible = false;
if (this.FileUpload1.HasFile)
{
string strFile = this.FileUpload1.FileName.Substring(0,this.FileUpload1.FileName.Length-4) + DateTime.Now.ToString("hhmmss") + ".ppt";
this.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile));
Presentation pres = null;
try
{
pres = lockPPT(new Presentation(Server.MapPath(strFile)));
}
catch (UnsupportedFormatException ex)
{
this.Label1.Visible = true;
this.Label1.Text = ex.Message;
return;
}
downloadPPT(pres, strFile);
}
}
public void downloadPPT(Presentation pres, string strFileName)
{
pres.Save(strFileName,Aspose.Slides.Export.SaveFormat.Ppt,Response,false);
Response.End();
}
public Presentation lockPPT( Presentation pres )
{
foreach (Slide sld in pres.Slides)
foreach (Shape shp in sld.Shapes)
shp.Protection = ShapeProtection.LockSelect;
return pres;
}
public Presentation unlockPPT(Presentation pres)
{
foreach (Slide sld in pres.Slides)
foreach (Shape shp in sld.Shapes)
shp.Protection = ShapeProtection.Unlocked;
return pres;
}
protected void btn_Unlock_Click(object sender, EventArgs e)
{
if (this.FileUpload1.HasFile)
{
string strFile = this.FileUpload1.FileName.Substring(0, this.FileUpload1.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") + ".ppt";
this.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile));
Presentation pres = null;
try
{
pres = unlockPPT(new Presentation(Server.MapPath(strFile)));
}
catch (UnsupportedFormatException ex)
{
this.Label1.Visible = true;
this.Label1.Text = ex.Message;
return;
}
downloadPPT(pres,strFile);
}
}
}
}
|
|
|
|