<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Ivy.wf().documents() - How to update an existing document with new content?</title><link>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content</link><description>&lt;p&gt;I got an error when trying to update the content for an existing document that's managed by &lt;code&gt;Ivy.wf().documents()&lt;/code&gt;. This api doesn't have the method &lt;code&gt;update&lt;/code&gt; so I just tried with following code:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ivy.wf.documents().add("newfolder\\hello.pdf").write().withContentFrom(new File("sourcefolder\\file2.pdf", false));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The message looks like: &lt;/p&gt;
&lt;p&gt;&lt;code&gt;IOException: File newfolder\hello.pdf already exists
PersistencyException: Cannot create file 'D:\work\AxonIvyDesigner6.3.0\files\application\newfolder\hello.pdf' for document 'newfolder\hello.pdf'&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Yeah! it's correct! But, I want to update this existing file with new content.&lt;/p&gt;
&lt;p&gt;I already tried to use method &lt;code&gt;delete&lt;/code&gt; first:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ivy.wf.documents().delete(new ch.ivyteam.ivy.workflow.document.Path("newfolder\\hello.pdf"));&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Or, trying to delete the physical file; but it did not work.&lt;/p&gt;
&lt;p&gt;Thanks for your checking!&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 27 Oct 2016 07:17:47 -0400</lastBuildDate><item><title>Comment by nvhuong on Reguel Wermelinger's answer</title><link>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content#2141</link><description>&lt;p&gt;Thank you! I got it.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nvhuong</dc:creator><pubDate>Thu, 27 Oct 2016 07:17:47 -0400</pubDate><guid>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content#2141</guid></item><item><title>Comment by nvhuong on Reto Weiss's answer</title><link>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content#2140</link><description>&lt;p&gt;Thank you. It works. I think it was just because I made a mistake with the string of path. it should be "newfolder/hello.pdf" rather than "newfolder\hello.pdf"&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nvhuong</dc:creator><pubDate>Thu, 27 Oct 2016 07:03:30 -0400</pubDate><guid>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content#2140</guid></item><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content/2136</link><description>&lt;p&gt;Update of a existing document should work with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ivy.wf.documents().get(new Path("/test")).write().withContentFrom(in.file);
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Mon, 24 Oct 2016 17:24:49 -0400</pubDate><guid>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content/2136</guid></item><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content/2133</link><description>&lt;p&gt;I agree that the update methods are missing. However you get an existing document with the workflowDocument API and update it with the &lt;code&gt;ch.ivyteam.ivy.scripting.objects.File&lt;/code&gt; api:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;private static void update(IDocument document) throws IOException {
    Path path = document.getPath();
    ch.ivyteam.ivy.scripting.objects.File myFile = 
            new ch.ivyteam.ivy.scripting.objects.File(path.toString());
    myFile.write("new content "+new Date());
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 24 Oct 2016 10:18:58 -0400</pubDate><guid>https://answers.axonivy.com/questions/2128/ivy-wf-documents-how-to-update-an-existing-document-with-new-content/2133</guid></item></channel></rss>