Uploading a csv file into a BLOB field without poping up the import dialog box.

Hi everyone,

So currently I am trying to import a CSV file to a staging table via a Dataport, While the data from the csv file gets stored in the staging table perfectly. I also simultaneously need the CSV file itself to be stored in the table as a Blob field.

I tried to use the import function, But the problem is I get 2 dialog box for choosing the file when this process is run, The first dialog box is because of the dataport and the 2nd one is because of the import function I used for the BLOB field.

I would be much obliged if someone could throw in some light on what is the right approach in this situation to save the CSV file inside a blob field.

Thank you,
Mathan

Hi Mathan,

So you want to import the whole CSV file into a staging table and use a dataport? As you have already noticed then it imports the data fields correctly.

But if you need to import the whole file, then you cannot use the dataport to import. Then you need to read the file directly and steam it into the blob field.

Hi Erik,

Thanks for your response. I actually want to do both the process, First I want my dataport to import all the data fields inside the csv file to a staging table and then i need this uploaded CSV file to be inserted as a blob field.

The first part of importing the data field from the CSV file to a staging table works perfectly via dataport, The next part is where i need some advice, i have used the import fuction for uploading the current proceesing CSV file into the blob field. Because of this import function NAV again asks for another import file with a pop up dialogue box, This is the reason for the 2 dialog box when i run this. But i dont want the 2nd dialog box to appear. I dont want to upload the same CSV file twice. I just want to upload the file which is currently being processed by the dataport.

When the file is in the processing status is there anyother way to update the CSV file as a blob field?

You can try (no guarantee that it works) to try the following (syntax not checked, just writing out of my mind):

f.WRITEMODE(FALSE);
f.OPEN(CurrDataport.FILENAME);
f.CREATEINSTREAM(Instrm);
Rec.BLOB.CREATEOUTSTREAM(OutStrm);
COPYSTREAM(OutStrm, InStrm);
f.CLOSE;

This code might work in the “OnPreDatatport” trigger.

But you need to make sure that you save the record to the database somehow. This is not done automatically after assigning the content to the BLOB field.

Hi Thomas,

Thank you soo much, I tried just as you suggested and it worked like a charm.

For verification, i used a code similar to below for reading the stored BLOB file.

Rec.CALFIELD(pdf);

Rec.pdf.EXPORT(‘c:\temp.pdf’);

SHELL(‘cmd/c c:\temp.pdf’); or HYPERLINK(‘c:\temp.pdf’);

ERASE(‘c:\temp.pdf’);

When i used this to read, It works fine, But it requires Adminstrator privileges to run the NAV. Is there any workaround for this? Like without the use of admin privileges.

Problem might be that you use “c:\temp.pdf”.

the root of you c drive is protected.

consider TEMPORARYPATH + ‘\temp.pdf’ instead:

Rec.CALFIELD(pdf);
Filename := TEMPORARYPATH + ‘\temp.pdf’;
f.WRITEMODE(TRUE);
f.CREATE(Filename);
f.CREATEOUTSTREAM(OutStrm);
Rec.pdf.CREATEINSTREAM(InStrm);
COPYSTREAM(OutStrm, InStrm);
f.CLOSE;
HYPERLINK(Filename);
ERASE(FILENAME);

Thank you Thomas.