| |
| 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="vb" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true" CodeBehind="Lock-Presentation.aspx.vb" 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>
|
| Visual Basic |
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
|
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Aspose.Slides
Namespace Lock_Presentation
Partial Public Class Lock_Presentation
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub btn_Download_Click(ByVal sender As Object, ByVal e As EventArgs)
Me.Label1.Visible = False
If Me.FileUpload1.HasFile Then
Dim strFile As String = Me.FileUpload1.FileName.Substring(0,Me.FileUpload1.FileName.Length-4) + DateTime.Now.ToString("hhmmss") & ".ppt"
Me.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile))
Dim pres As Presentation = Nothing
Try
pres = lockPPT(New Presentation(Server.MapPath(strFile)))
Catch ex As UnsupportedFormatException
Me.Label1.Visible = True
Me.Label1.Text = ex.Message
Return
End Try
downloadPPT(pres, strFile)
End If
End Sub
Public Sub downloadPPT(ByVal pres As Presentation, ByVal strFileName As String)
pres.Save(strFileName,Aspose.Slides.Export.SaveFormat.Ppt,Response,False)
Response.End()
End Sub
Public Function lockPPT(ByVal pres As Presentation) As Presentation
For Each sld As Slide In pres.Slides
For Each shp As Shape In sld.Shapes
shp.Protection = ShapeProtection.LockSelect
Next shp
Next sld
Return pres
End Function
Public Function unlockPPT(ByVal pres As Presentation) As Presentation
For Each sld As Slide In pres.Slides
For Each shp As Shape In sld.Shapes
shp.Protection = ShapeProtection.Unlocked
Next shp
Next sld
Return pres
End Function
Protected Sub btn_Unlock_Click(ByVal sender As Object, ByVal e As EventArgs)
If Me.FileUpload1.HasFile Then
Dim strFile As String = Me.FileUpload1.FileName.Substring(0, Me.FileUpload1.FileName.Length - 4) + DateTime.Now.ToString("hhmmss") & ".ppt"
Me.FileUpload1.PostedFile.SaveAs(Server.MapPath(strFile))
Dim pres As Presentation = Nothing
Try
pres = unlockPPT(New Presentation(Server.MapPath(strFile)))
Catch ex As UnsupportedFormatException
Me.Label1.Visible = True
Me.Label1.Text = ex.Message
Return
End Try
downloadPPT(pres,strFile)
End If
End Sub
End Class
End Namespace
|
|
|
|