2 qq 24259127 qq_24259127 于 2016.04.25 17:28 提问

C#导出到Microsoft Project中,出现“参数值无效”错误 50C

以下是调用方法

 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();
    }

报的错误如下:
(http://img.ask.csdn.net/upload/201604/25/1461576321_401866.jpg)

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!