<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Best way to download files from Windchill Server to client in Windchill Customization</title>
    <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943639#M7923</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/821503"&gt;@mprotas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is that you can not use the reset method to reset the response.&lt;/P&gt;
&lt;P&gt;If you use the reset, then you lost the connection to your wizard window.&lt;/P&gt;
&lt;P&gt;Remove it.&lt;/P&gt;
&lt;P&gt;You need to solve the&amp;nbsp;&lt;STRONG&gt;IllegalStateException&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;issue, and .reset method is not the solution.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2024 12:27:54 GMT</pubDate>
    <dc:creator>HelesicPetr</dc:creator>
    <dc:date>2024-04-15T12:27:54Z</dc:date>
    <item>
      <title>Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/858903#M2343</link>
      <description>&lt;P&gt;I'm looking to download a zip from my windchill server(temp location) to the client machine.&lt;/P&gt;&lt;P&gt;The zip was actually created as a result of an custom action.&lt;/P&gt;&lt;P&gt;So basically, when I click on the action a zip should get downloaded, that's my requirement.&lt;/P&gt;&lt;P&gt;Please suggest me your ideas or share me any existing solution.&lt;/P&gt;&lt;P&gt;Many thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;FONT color="headerbuttontrackingcode"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="headerbuttontrackingcode"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 14:02:00 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/858903#M2343</guid>
      <dc:creator>MV_10441462</dc:creator>
      <dc:date>2024-03-15T14:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/858910#M2344</link>
      <description>&lt;P&gt;I did this with a JSP tied to that custom action:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;BOMExportExcelUtility excelUtil=BOMExportExcelUtilityImpl.createBOMExportExcelUtility();
                    //7. Sub-module create Excel File for user download
                    response.reset();
                    excelUtil.createExcelFile(response.getOutputStream(),sheet1,sheet2);
                    ServletOutputStream outs = response.getOutputStream();
                    response.setHeader("Content-type","application/ms-excel");
                    String version=VersionControlHelper.getVersionIdentifier((Versioned)bom).getValue();
                    if (version.indexOf('.')!=-1)
                        version=version.substring(0, version.indexOf('.')); //just get first part
                    
                    String filename=bom.getNumber()+version;
                    response.setHeader("Content-disposition","attachment; filename="+filename+".XLS");//should prompt for download
                    
                    excelUtil.writeFile();
                    //8. Return response to user's browser session.
                    outs.flush();
                    outs.close();&lt;/LI-CODE&gt;
&lt;P&gt;This is the section where my code creates an XLS file and streams it back to the client. User downloads the file.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2023 15:28:58 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/858910#M2344</guid>
      <dc:creator>avillanueva</dc:creator>
      <dc:date>2023-02-28T15:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859079#M2345</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/642430"&gt;@MV_10441462&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example&amp;nbsp;&amp;nbsp;from&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/27334"&gt;@avillanueva&lt;/a&gt; is very good one how to download file.&lt;/P&gt;
&lt;P&gt;I would add that you need to write own sollution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create zip in java&lt;/P&gt;
&lt;P&gt;Collect files from Windchill&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add files to the zip&lt;/P&gt;
&lt;P&gt;push the zip stream to the client user&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 06:30:14 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859079#M2345</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2023-03-01T06:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859080#M2346</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/241117"&gt;@HelesicPetr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me with the snippet to push the zip stream to client user?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 06:33:35 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859080#M2346</guid>
      <dc:creator>MV_10441462</dc:creator>
      <dc:date>2023-03-01T06:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859096#M2347</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/642430"&gt;@MV_10441462&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;depends how do you start your function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;usually you get request and get the outputstream from it and flush (send) the data to the client as &lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/27334"&gt;@avillanueva&lt;/a&gt;'s example shows you. .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is short snip with a zipStream but you need to learn how to add files to the zip stream&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;HTTPResponse resp; // you need to get respons from commandBean or whereever HttpServletResponse response = nmCommandBean.getResponse(); 

ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
CheckedOutputStream checksum = new CheckedOutputStream(zipOut, new Adler32());
ZipOutputStream zipOutputStream = new ZipOutputStream(new BufferedOutputStream(checksum));

InputStream contentStream = ContentServerHelper.service.findContentStream(appDatatToZip);
		// definice filename s cestou v zip
String fileZipEntry = appDatatToZip.getFileName();
addStreamToZip(fileZipEntry, zipOutputStream, contentStream); // annother sub method where the content is writen to zip

zipOutputStream.close();
		
OutputStream output = resp.getOutputStream();

resp.setHeader("Content-disposition", "attachment; filename=zipDownloadFile.zip");
resp.setHeader("Content-Type", "application/zip");

output.write(zipOut.toByteArray()); // zip stream written to the respons outputStream

output.flush();
output.close();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 08:07:58 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/859096#M2347</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2023-03-01T08:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943617#M7918</link>
      <description>&lt;P&gt;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/241117"&gt;@HelesicPetr&lt;/a&gt;- how can I overwrite the &lt;STRONG&gt;HttpServletResponse&lt;/STRONG&gt; from &lt;STRONG&gt;NmCommandBean::getResponse()&lt;/STRONG&gt; when whenever I try to use this method I retrieve &lt;STRONG&gt;IllegalStateException&lt;/STRONG&gt; - Already using writer?&lt;/P&gt;&lt;P&gt;I want to perform downloading .zip file generated on the server-side from Wizard's &lt;EM&gt;FormProcessor&lt;/EM&gt;. Is there any solution for that? Here is my example code of custom &lt;EM&gt;FormProcessor&lt;/EM&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;private ExportPackageFileManager fileManager;

    @Override
    public FormResult doOperation(NmCommandBean nmCommandBean, List&amp;lt;ObjectBean&amp;gt; list) throws WTException {
        FormResult result = super.doOperation(nmCommandBean, list);
        WTPart contextPart = (WTPart) WizardUtils.getContextObject(nmCommandBean);
        setFileManager(contextPart);

        HttpServletResponse response = nmCommandBean.getResponse();
        Path path = fileManager.getZipFilePath();
        String fileName = path.getFileName().toString();

        response.reset();
        try(ServletOutputStream outputStream = response.getOutputStream()) {
            response.setStatus(200);
            response.setHeader("X-Content-Type-Options", null);
            response.setHeader("Content-Type", "application/zip");
            response.setHeader("Content-disposition", "attachment; filename=" + fileName);
            response.setContentLength((int) path.toFile().length());
            Files.copy(path, outputStream);
            result.addDynamicRefreshInfo(new DynamicRefreshInfo(contextPart, contextPart, DynamicRefreshInfo.Action.UPDATE));
            return result;
        } catch (IOException | IllegalStateException e) {
            throw new WTException("Could not send file!");
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Whole logic for fetching files, zipping them works just fine. Whenever I click "Submit" button on my Wizard - window freezes and won't close automatically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;response.reset() is being used to avoid getting IllegalStateException but on the other hand it causes the window to freeze.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 11:14:49 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943617#M7918</guid>
      <dc:creator>mprotas</dc:creator>
      <dc:date>2024-04-15T11:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943629#M7920</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/821503"&gt;@mprotas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you use the file.copy?&lt;/P&gt;
&lt;P&gt;try to use the&amp;nbsp;output.write() with transferred file to the byte.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 11:57:40 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943629#M7920</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2024-04-15T11:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943638#M7922</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/241117"&gt;@HelesicPetr&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Changing from Files.copy() to more extensive writing to &lt;STRONG&gt;OutputStream&lt;/STRONG&gt; object do not change anything in the freezing of Wizard's window after performing download of .zip file.&lt;/P&gt;&lt;P&gt;It looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the current version of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;@Override
    public FormResult doOperation(NmCommandBean nmCommandBean, List&amp;lt;ObjectBean&amp;gt; list) throws WTException {
        FormResult result = super.doOperation(nmCommandBean, list);
        WTPart contextPart = (WTPart) WizardUtils.getContextObject(nmCommandBean);
        setFileManager(contextPart);

        HttpServletResponseWrapper response =  new HttpServletResponseWrapper(nmCommandBean.getResponse());
        Path path = fileManager.getZipFilePath();
        String fileName = path.getFileName().toString();

        response.reset();
        try(ServletOutputStream outputStream = response.getOutputStream()) {
            response.setStatus(200);
            response.setHeader("X-Content-Type-Options", null);
            response.setHeader("Content-Type", "application/zip");
            response.setHeader("Content-disposition", "attachment; filename=" + fileName);
            response.setContentLength((int) path.toFile().length());
            //Files.copy(path, outputStream);
            File file = new File(fileManager.getZipFilePath().toString());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try(FileInputStream fis = new FileInputStream(file)) {
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
            }
            catch (IOException e) {
                System.out.println("Test");
            }
            outputStream.write(bos.toByteArray());
            outputStream.flush();
            outputStream.close();
            result.addDynamicRefreshInfo(new DynamicRefreshInfo(contextPart, contextPart, DynamicRefreshInfo.Action.UPDATE));
            return result;
        } catch (IOException | IllegalStateException e) {
            throw new WTException("Could not send file!");
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 12:24:01 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943638#M7922</guid>
      <dc:creator>mprotas</dc:creator>
      <dc:date>2024-04-15T12:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943639#M7923</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/821503"&gt;@mprotas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The point is that you can not use the reset method to reset the response.&lt;/P&gt;
&lt;P&gt;If you use the reset, then you lost the connection to your wizard window.&lt;/P&gt;
&lt;P&gt;Remove it.&lt;/P&gt;
&lt;P&gt;You need to solve the&amp;nbsp;&lt;STRONG&gt;IllegalStateException&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;issue, and .reset method is not the solution.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 12:27:54 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943639#M7923</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2024-04-15T12:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943643#M7924</link>
      <description>&lt;P&gt;Yeah, but without this reset() method I receive that IllegalStateException mentioned above. Is there any workaround to perform downloading file from FormProcessor Wizard's window?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 12:29:16 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943643#M7924</guid>
      <dc:creator>mprotas</dc:creator>
      <dc:date>2024-04-15T12:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943646#M7925</link>
      <description>&lt;P&gt;&lt;a href="https://community.ptc.com/t5/user/viewprofilepage/user-id/821503"&gt;@mprotas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the export mechanism used for downloading a WTDocument objects to a zip file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PetrH&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2024 12:40:35 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/943646#M7925</guid>
      <dc:creator>HelesicPetr</dc:creator>
      <dc:date>2024-04-15T12:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to download files from Windchill Server to client</title>
      <link>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/987821#M9115</link>
      <description>&lt;P&gt;Hi HelesicPetr,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using same and executing from one of action. On click of action&lt;SPAN&gt;&amp;nbsp;excel file is getting created on defined location and&amp;nbsp; DoOperation() form processor method also executing well without any errors but created file not getting downloaded on client browser as well as Feedback MSG also not reflecting on UI only page getting refreshed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Need assistance for this scenario.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 12:38:06 GMT</pubDate>
      <guid>https://community.ptc.com/t5/Windchill-Customization/Best-way-to-download-files-from-Windchill-Server-to-client/m-p/987821#M9115</guid>
      <dc:creator>@_1647</dc:creator>
      <dc:date>2024-12-09T12:38:06Z</dc:date>
    </item>
  </channel>
</rss>

