例外无法打开文件请帮我解决 [英] Exception could not open file plese help me to solve
问题描述
i
i创建了一个应用程序,将文件上传到文件夹,然后从该文件夹中获取文件并将其转换为图像。
这里是代码
i
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;
//UPLOADS THE FILE INTO THE FOLDER
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]
推荐答案
您好,我想到的第一件事是您的代码行:
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));
认为这可能对您有所帮助,因为当您调用下一行代码时,它返回文件夹NewFolder1的完整路径:
Server.MapPath(〜/ NewFolder1) - >将是这样的(c:\inetpub\wwwroot\mysite\\\
ewfolder1);
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);
这篇关于例外无法打开文件请帮我解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!