5 Replies Latest reply on Oct 20, 2009 11:46 AM by Serhiy Zastavnyy

    Open files mpp in new window

    roberto moreno Newbie

      Hi,

      I want view a mpp file in Java with RichFaces. When you click the view button, I opened on the same screen and in format of text. This is my code:

      ServletOutputStream op = null;
      DataInputStream in = null;
      HttpServletResponse resp = FacesUtil.getResponse();
      FacesContext facesContext = FacesContext.getCurrentInstance();

      try {

      String fileName = "C:\\Transferencias.mpp";
      String orig_fileName = "C:\\TransferenciasNuevo.mpp";

      File f = new File(fileName);
      int length = 0;

      op = resp.getOutputStream();
      in = new DataInputStream(new FileInputStream(f));

      resp.setContentType("application/vnd.ms-project");
      resp.setContentLength( (int)f.length() );
      resp.setHeader( "Content-Disposition", "attachment; filename=\"" + orig_fileName + "\"" );


      byte[] bbuf = new byte[1024];
      while ((in != null) && ((length = in.read(bbuf)) != -1))
      {
      op.write(bbuf,0,length);
      }

      op.flush();

      in.close();
      op.close();
      } catch (ClientAbortException e) {
      // Ante cualquier tipo de error intentamos
      // cerrar los stream para no dejarlos bloqueados
      // e.printStackTrace();

      try {
      if (in != null) {
      in.close();
      }
      if (op != null) {
      op.close();
      }
      } catch (ClientAbortException e2) {
      // e2.printStackTrace();
      }
      }

      facesContext.responseComplete();

      When you run it gives me no errors, but does not open properly

      Thanks.