protected void ClickToProtect_Click(object sender, EventArgs e) { if (this.FileUpload1.HasFile) { string fileName = Path.GetFileNameWithoutExtension(this.FileUpload1.PostedFile.FileName); string ext = Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower(); if (ext == ".pptx") { Stream readFile = this.FileUpload1.PostedFile.InputStream; try { // Opens the specified presentation IPresentation presentation = Presentation.Open(readFile); if (txtEnOpen.Text == null) { txtEnOpen.Text = string.Empty; } //Set the write protection for the presentation presentation.SetWriteProtection(txtEnOpen.Text); //saves the presentation presentation.Save("WriteProtection.pptx", FormatType.Pptx, Response); } catch (Exception ex) { this.label1.Text = "Please Check the password"; } } } }
/// <summary> /// Encrypt the word document /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void protect_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(passwordBox1.Password)) { MessageBox.Show("Please enter password to protect", "Password Missing", MessageBoxButton.OK); } else { //Creates instance for presentation IPresentation presentation = Presentation.Open(textBox1.Tag.ToString()); //Set the write protection for presentation instance presentation.SetWriteProtection(passwordBox1.Password); //Saving the presentation presentation.Save("WriteProtection.pptx"); //Closing the presentation presentation.Close(); if (MessageBox.Show("Do you want to view the protected Presentation?", "Write Protected Presentation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("WriteProtection.pptx"); } } } catch (Exception exp) { MessageBox.Show("This file could not be write protected , please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); } }
public ActionResult WriteProtection(string Browser, string Password) { string basePath = _hostingEnvironment.WebRootPath; FileStream fileStreamInput = new FileStream(basePath + @"/Presentation/Syncfusion Presentation.pptx", FileMode.Open, FileAccess.Read); //Open a existing PowerPoint presentation. IPresentation presentation = Presentation.Open(fileStreamInput); if (Password == null) { Password = string.Empty; } //Set the write protection for presentation instance presentation.SetWriteProtection(Password); MemoryStream ms = new MemoryStream(); //Initialize the file stream to download the presentation. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation"); //Set the file name. fileStreamResult.FileDownloadName = "ProtectedPresentation.pptx"; //Saves the presentation to the memory stream. presentation.Save(ms); //Set the position of the stream to beginning. ms.Position = 0; return(fileStreamResult); }
public ActionResult WriteProtection(string Password1) { string file = ResolveApplicationDataPath("Syncfusion Presentation.pptx"); //Open a existing PowerPoint presentation IPresentation presentation = Syncfusion.Presentation.Presentation.Open(file); if (Password1 == null) { Password1 = string.Empty; } //Set the write protection for presentation instance presentation.SetWriteProtection(Password1); return(new PresentationResult(presentation, "WriteProtection.pptx", HttpContext.ApplicationInstance.Response)); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Assembly assembly = typeof(GettingStartedPresentation).GetTypeInfo().Assembly; string resourcePath = "Syncfusion.SampleBrowser.UWP.Presentation.Presentation.Assets.Transition.pptx"; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); //Open existing PowerPoint presentation. IPresentation presentation = await Presentation.OpenAsync(fileStream); if (txtUserPassword.Password == null) { txtUserPassword.Password = string.Empty; } //Set write protection for the PowerPoint presentation. presentation.SetWriteProtection(txtUserPassword.Password); MemoryStream ms = new MemoryStream(); SavePPTX(presentation); }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.Presentation.Templates.Transition.pptx"; Assembly assembly = Assembly.GetExecutingAssembly(); Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); //Set the write protection for presentation instance presentation.SetWriteProtection("syncfusion"); MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("WriteProtection.pptx", "application/powerpoint", stream, m_context); } }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.Transition.pptx"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.Transition.pptx"; #endif Assembly assembly = typeof(WriteProtection).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); //Open a existing PowerPoint presentation IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); string protectPassward = string.Empty; if (password != null && password.Text != null) { protectPassward = password.Text; } //Set the write protection for presentation instance presentation.SetWriteProtection(protectPassward); MemoryStream stream = new MemoryStream(); presentation.Save(stream); presentation.Close(); stream.Position = 0; if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("WriteProtection.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("WriteProtection.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
/// <summary> /// Create a write protection Presentation document /// </summary> /// <returns>Return the created Presentation document as stream</returns> public MemoryStream CreateWriteProtectionPresentation(string Password) { //Open the existing presentation FileStream fileStreamInput = new FileStream(basePath + "Transition.pptx", FileMode.Open, FileAccess.Read); //Open a existing PowerPoint presentation. IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStreamInput); if (Password == null) { Password = string.Empty; } //Set the write protection for presentation instance presentation.SetWriteProtection(Password); //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created PowerPoint document to MemoryStream presentation.Save(stream); return(stream); } }