Click here to Skip to main content
12,821,494 members (27,368 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

i have created an app that uploads files to a folder and then takes the files from that folder and convert it to images.
here is the code
if (FileUpload1.HasFile)
                  string file = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName);
                  string filname = FileUpload1.PostedFile.FileName;
                  FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\NewFolder1\\") + FileUpload1.FileName);
//TAKES THE PATH and file
                  string strPath = Server.MapPath(Request.ApplicationPath) + "~/NewFolder1/" + filname;
//assign the file to ppt
ApplicationClass pptApplication = new ApplicationClass();
                  Presentation pptPresentation = pptApplication.Presentations.Open(strPath, MsoTriState.msoFalse,
                  MsoTriState.msoFalse, MsoTriState.msoFalse);
                  var slides = new List<string>();
                  targetPath = Server.MapPath("~/NewFolder1/");
                  targetPath += "\\{0}";
                  for (var i = 1; i <= pptPresentation.Slides.Count; i++)

but when i run the app it gives the follwoing error.
System.Runtime.InteropServices.COMException: PowerPoint could not open the file.
Presentation pptPresentation = pptApplication.Presentations.Open(strPath, MsoTriState.msoFalse....

In this line of code i am getting this above exception
pptApplication.Presentations.Open(strPath, MsoTriState.msoFalse,
                  MsoTriState.msoFalse, MsoTriState.msoFalse);

[Edit]Code block added[/Edit]
Posted 22-Dec-12 1:39am
Updated 22-Dec-12 1:42am
jibesh 22-Dec-12 8:41am
Please do not post the same question again and again with different header.

you may edit your question using the green 'Improve Question' link at the right bottom of your question to modify. do value others time posting redundant answers to the same questions multiple time.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi , firts thing that come to my mind is the line of your code:
string strPath = Server.MapPath(Request.ApplicationPath) + "~/NewFolder1/" + filname;

Maybe it could be reasonable to change it with next line:

string strPath = Server.MapPath(System.IO.Path.Combine("~/NewFolder1" , filname));

think this might help you, because when you invoke next line of code , it return the full path to folder "NewFolder1" :
Server.MapPath("~/NewFolder1") -> will be something like that (c:\inetpub\wwwroot\mysite\newfolder1);
Member 9305115 23-Dec-12 22:58pm
Thank This is working for me...

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100