以下是调用方法
public void createMpp()
{
Object missing = Type.Missing;
ApplicationClass prj = new ApplicationClass();
PjFileFormat format = PjFileFormat.pjMPP;//format定义
prj.Visible = true;
prj.FileNew(missing, missing, missing, false);
Project myProject = prj.ActiveProject;
Task task = null;
task = myProject.Tasks.Add("zhi", 1);
task.Start = "2008-8-1";
task.Finish = "2008-8-18";
string filename = Server.MapPath("test.mpp");
prj.FileSaveAs(filename, format, false, false, false, false, null, null, null, null,
null, null, null, false, false, false, false, null, false);
prj.Quit(PjSaveType.pjSave);
System.IO.FileInfo file = new System.IO.FileInfo(filename);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
//Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("订单列表.xls"));
Response.AddHeader("Content-Disposition", "attachment;filename="+ HttpUtility.UrlEncode("test.mpp"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/vnd.ms-project";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
// 停止页面的执行
Response.End();
}
报的错误如下:
(https://img-ask.csdn.net/upload/201604/25/1461576321_401866.jpg)