I am trying to add an image to a web app version of Aspose.Slides.
1) Is it possible to use relative URLs
2) I am getting the following error when trying to add image (and the path is correct):
The error is listed first, the complete code follows…
Could not find file ‘D:\3800-00879.jpg’.
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
<br><br>
<b> Exception Details: </b>System.IO.FileNotFoundException: Could not find file 'D:\3800-00879.jpg'.<br><br>
<b>Source Error:</b> <br><br>
<table bgcolor="#ffffcc" width="100%">
<tbody><tr>
<td>
<code></code><pre>Line 78: shape.FillFormat.Type = FillType.Picture;
Line 79: //Creating a picture object that will be used to fill the ellipse
Line 80: Picture pic = new Picture(pres, @“D:\3800-00879.jpg”);
Line 81: //Adding the picture object to pictures collection of the presentation
Line 82: //After the picture object is added, the picture is given a uniqe picture Id
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using Aspose.Slides;
namespace Aspose.Slides.WF.Template
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region open presentation and set up license
//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation(“D:\\a Web Development\temp\hello.ppt”);
//Create a License object
License license = new License();
//Set the license of Aspose.Slides for .NET to avoid the evaluation limitations
license.SetLicense(“Aspose.Slides.lic”);
#endregion
#region Reading and Modifying document properties
//Create a reference to DocumentProperties associated with Presentation
DocumentProperties dp = pres.DocumentProperties;
//Accessing the built-in properties of the presentation
System.Console.WriteLine("Author: " + dp.Author);
System.Console.WriteLine("Title: " + dp.Title);
System.Console.WriteLine("Company: " + dp.Company);
System.Console.WriteLine("Comments: " + dp.Comments);
System.Console.WriteLine("Subject: " + dp.Subject);
//Modifying the built-in properties of the presentation
dp.Author = “Salman Sarfraz”;
dp.Title = “Modifying Presentation Properties”;
dp.Company = “Aspose Pty. Ltd.”;
dp.Comments = “Modified Presentation Properties”;
dp.Subject = “Presentation Properties”;
#endregion
#region Locking a presentation
//A presentation is composed of slides and each slide may have a number of elements. In general, every element of the slide is considered as a shape. Aspose.Slides for .NET provides a unique feature of locking the shape. In this way, whole presentation may be locked and hence can’t be edited unless it is unlocked through Aspose.Slides for .NET.
//Loop through all the slides in the presentation
foreach (Slide sld in pres.Slides)
//Loop through all the shapes in the slide
foreach (Shape shp in sld.Shapes)
//Lock each shape to be protected against the select
shp.Protection = ShapeProtection.LockSelect;
#endregion
//Printing the total number of slides present in the presentation
Label1.Text = pres.Slides.Count.ToString();
//Adding an empty slide to the presentation and getting the reference of that empty slide
Slide slide = pres.AddEmptySlide();
Shape shape = slide.Shapes.AddEllipse(1400, 1200, 3000, 2000);
shape.FillFormat.Type = FillType.Picture;
Picture pic = new Picture(pres, @“D:\3800-00879.jpg”);
int picId = pres.Pictures.Add(pic);
shape.FillFormat.PictureId = picId;
pres.Masters[0].Background.FillFormat.ForeColor = Color.Blue;
pres.Slides.RemoveAt(0);
#region stream presentation to output as file download
//Setting the content type of the Http Response
this.Response.ContentType = “application/vnd.ms-powerpoint”;
//Appending the header of the Http Response to contain the presentation file name
this.Response.AppendHeader(“Content-Disposition”, “attachment; filename=hello.ppt”);
//Flushing the buffers of Http Response
this.Response.Flush();
//Accessing the output stream of Http Response
System.IO.Stream st = this.Response.OutputStream;
//Saving the presentation to the output stream of Http Response
pres.Write(st);
//Closing the Http Response
this.Response.End();
#endregion
}
}
}