Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have a web page and i want to upload ppt file on it,convert it into imgage in show it into an image tag. the ppt file has one slide. here is the code:
protected void Page_Load(object sender, EventArgs e)
{
    ApplicationClass pptApplication = new ApplicationClass();
    Presentation pptPresentation = pptApplication.Presentations.Open("saifullah.ppt", MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);

    pptPresentation.Slides[1].Export("slid.jpg", "jpg", 320, 240);
    Image1.ImageUrl = pptPresentation.ToString();
}


When I debug the page it shows the following output instead of image.

Submit Query


Can somebody tell me where the problem is?

Thanks for your time!
Posted
Updated 25-Oct-11 2:38am
v2
Comments
E.F. Nijboer 25-Oct-11 8:27am    
The security risk of doing something like this is outrageous. It's like saying, upload any executable and I will execute it.
saifullahiit 25-Oct-11 8:35am    
same type of code is also given in:
http://stackoverflow.com/questions/2653740/problems-with-office-automation-in-asp-net-i-can-use-alternatives-such-as-open
http://stackoverflow.com/questions/2972263/ppt-slides-to-images
so its not something risky it just convert your ppt file into image so that user wont download them as ppt.
if you can solve the given issue, it will be much appreciable.
E.F. Nijboer 25-Oct-11 15:24pm    
Have you read the microsoft page? You can find it in your first link. It is one in a list of quite some problems with server-side automation.
http://support.microsoft.com/kb/257757

1 solution

Here's the problem in your code:

C#
protected void Page_Load(object sender, EventArgs e)
{
    ApplicationClass pptApplication = new ApplicationClass();
    Presentation pptPresentation = pptApplication.Presentations.Open("saifullah.ppt", MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);
    // Here you export the  slide as a JPG file which is OK
    // You should also specify a path in your file system where to the export should take place
    // and additionally this path should be exposed under some URL on your host
    String filePath;
    filePath = Server.MapPath("/Some/Virtual/Path/on/your/WebSite");
    filePath += "\\{0}";
    String fileName = "slid.jpg"; // This should be dynamic too so you can have more that one picture of a slide
    String fileNameAndPath = String.Format(filePath, "slid.jpg");
    pptPresentation.Slides[1].Export(fileNameAndPath, "jpg", 320, 240);
    Image1.ImageUrl = String.Format("/Some/Virtual/Path/on/your/WebSite/{0}", fileName);
}


Regards,

—MRB
 
Share this answer
 
Comments
saifullahiit 25-Oct-11 8:57am    
thanks MRB it worked, you are the gr8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900