<?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 how to read CSV file from alfresco repository in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94286#M27842</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have stored CSV file in repository using bulk import .Now I want to read that CSV file in my java class .Also I have noderef of the particular CSV file.&lt;/P&gt;&lt;P&gt;Kindly suggest API's/Sample code to read CSV file in alfresco .&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isha&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2020 09:47:41 GMT</pubDate>
    <dc:creator>Isha</dc:creator>
    <dc:date>2020-04-29T09:47:41Z</dc:date>
    <item>
      <title>how to read CSV file from alfresco repository</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94286#M27842</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have stored CSV file in repository using bulk import .Now I want to read that CSV file in my java class .Also I have noderef of the particular CSV file.&lt;/P&gt;&lt;P&gt;Kindly suggest API's/Sample code to read CSV file in alfresco .&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isha&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 09:47:41 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94286#M27842</guid>
      <dc:creator>Isha</dc:creator>
      <dc:date>2020-04-29T09:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to read CSV file from alfresco repository</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94287#M27843</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You can use ContentReader service read content of file.&lt;/P&gt;&lt;P&gt;&lt;A href="http://dev.alfresco.com/resource/AlfrescoOne/5.0/PublicAPI/org/alfresco/service/cmr/repository/ContentReader.html" target="_blank" rel="nofollow noopener noreferrer"&gt;http://dev.alfresco.com/resource/AlfrescoOne/5.0/PublicAPI/org/alfresco/service/cmr/repository/ContentReader.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 10:11:12 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94287#M27843</guid>
      <dc:creator>sp2</dc:creator>
      <dc:date>2020-04-29T10:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to read CSV file from alfresco repository</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94288#M27844</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/80752"&gt;@Isha&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use &lt;STRONG&gt;NodeService&lt;/STRONG&gt; (&lt;A href="https://docs.alfresco.com/6.1/references/dev-services-node.html" target="_self" rel="nofollow noopener noreferrer"&gt;NodeService Docs&lt;/A&gt;) to double check the node existance and get the name of csv file for creating a temp file which you will use during the processig of your program and at the end delete the temp csv file.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Use &lt;STRONG&gt;ContentService&lt;/STRONG&gt; (&lt;A href="https://docs.alfresco.com/6.1/references/dev-services-content.html" target="_self" rel="nofollow noopener noreferrer"&gt;ContentSerice Docs&lt;/A&gt;) to get the instance of ContentReader (as mentioned by Sanjay) for the csv nodeRef.&lt;/P&gt;

&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Pseudo Code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;File tempCSVFile = null;
try {
	if (csvNodeRef != null &amp;amp;&amp;amp; nodeService.exists(csvNodeRef)) {
	    final String csvFileName = (String) nodeService.getProperty(csvNodeRef, ContentModel.PROP_NAME); //get the file name from node.

		//create temp file in temp directory
		final File tempDir = new File(System.getProperty("java.io.tmpdir"));
		tempCSVFile = File.createTempFile(csvFileName, tempDir);
							
		final ContentReader reader = contentService.getReader(csvNodeRef, ContentModel.PROP_CONTENT);
		if (reader.getSize() &amp;gt; 0) {
			reader.getContent(tempCSVFile);
		}
		//Now you have csv temp file, you can read it as file input stream and process the stream
		final InputStream inStreamJson = Files.newInputStream(Paths.get(tempCSVFile));
		//Process the stream as needed.
		
	}
} catch(InvalidNodeRefException | ContentIOException nodeEx) {
  //log error appropriately 
} catch(AlfrescoRuntimeException alfEx) {
  //log error appropriately 
} catch(RuntimeException runEx) {
  //log error appropriately 
} catch(Exception excp) {
  //log error appropriately 
} finally {//delete temp csv file.
	if (tempCSVFile != null &amp;amp;&amp;amp; tempCSVFile.exists()) {
		tempCSVFile.delete();
	}
}&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 12:46:55 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-read-csv-file-from-alfresco-repository/m-p/94288#M27844</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-04-29T12:46:55Z</dc:date>
    </item>
  </channel>
</rss>

