cancel
Showing results for 
Search instead for 
Did you mean: 

Write to a CSV File in OnBase

Christopher_Per
Champ in-the-making
Champ in-the-making

Good Afternoon - 

 

I'm just wondering if it would be possible to edit a CSV via the API inside of OnBase. I know I can export the CSV file, edit it via either with System.IO or an office library. I just wanted to know if I can do this without having to export, make changes, and reimport into OnBase. 

 

We are currently on EP3, and using the Unity API

2 REPLIES 2

Scott_McLean
Elite Collaborator
Elite Collaborator

It's certainly doable. The basic process would be:

 

  1. Retrieve the document page data using the text data provider (app.Core.Retrieval.Text).
  2. Parse/edit the CSV data using whatever .NET CSV utility you prefer.
  3. Store the edited file back to OnBase (if you are licensed for EDM Services and the document is configured to allow revisions, you can store a new revision of the same document).

 

Update: Sorry - I just realized that you asked "without re-importing."
The answer to that is no. Once you modify the file, you do have to re-import, but you can do the re-import automatically via the API.

Mark_Queitzsch
Star Collaborator
Star Collaborator

Christopher, you could retrieve the PageData to a MemoryStream, manipulate that, and then save the MemoryStream using app.Core.Storage.StoreNewRevision(..) or using al alternative method according to how you want to store the revised document. The attached snippet demonstrates working with MemoryStream by taking a document, converting it to PDF and saving it as a rendition of the current document, all without saving to and reading back from disk.

 

using (PageData pageData = app.Core.Retrieval.PDF.GetDocument(args.Document.DefaultRenditionOfLatestRevision)){	using (MemoryStream memoryStream = new MemoryStream())	{		pageData.Stream.CopyTo(memoryStream);		memoryStream.Position = 0L;  // rewind the stream		StoreRenditionProperties rpPDF = app.Core.Storage.CreateStoreRenditionProperties(args.Document.LatestRevision, pdfType);		using (PageData pageDataPDF = app.Core.Storage.CreatePageData(memoryStream, pdfType.Extension))		{			PageData[] newPageData = new PageData[1];			newPageData[0] = pageDataPDF;			Document pdfDoc = app.Core.Storage.StoreNewRendition(newPageData, rpPDF);		}	}}