cancel
Showing results for 
Search instead for 
Did you mean: 

Blob object help

Former Member
0 Kudos

Hi

I want to ad a blob object into master data line table.

My table is @CT_PF_CMG1.

this is my code

CompanyService ocomp = connection.GetCompany().GetCompanyService();
            BlobParams param = ocomp.GetDataInterface(CompanyServiceDataInterfaces.csdiBlobParams) as BlobParams;
            param.Table = "@CT_PF_CMG1";
            param.Field = "U_Description"; //This fild is used to store base64 string ? if so what type has it be ?
            BlobTableKeySegment seg = param.BlobTableKeySegments.Add();
            seg.Name = "Code"; //is this correct this is document lines table 
            seg.Value = "qwe";
            BlobTableKeySegment seg2 = param.BlobTableKeySegments.Add();
            seg2.Name = "LineId";//is this correct this is document lines table 
            seg2.Value = "1";
            Blob oblob = ocomp.GetDataInterface(CompanyServiceDataInterfaces.csdiBlob) as Blob;
            string base64;
            using (System.IO.FileStream fs=new System.IO.FileStream(filename,System.IO.FileMode.Open               ))
            {
                long fsize = fs.Length;
                 byte[] buf = new byte[fsize];
                fs.Read(buf, 0, (int)fsize);
                fs.Close();
                base64 = Convert.ToBase64String(buf);
            }
            oblob.Content = base64;
            try
            {
                ocomp.SetBlob(param,oblob);
            }catch(Exception ex)
            {
            }

it throws an error

 "CCompanyServices::SetBlob Cannot update database; no records found."

Thanks for an advice .

Accepted Solutions (0)

Answers (1)

Answers (1)

Eneveux
Product and Topic Expert
Product and Topic Expert
0 Kudos

Michal,

Have a look at the GetBlob Method in the SAP Business One SDK Help as there is sample code there that you can review. Also, I am assuming you are using Business One 8.8 as Blob was introduced in version 8.8.

Eddy

Former Member
0 Kudos

Hi Edward

Unfortunately, these Help files don`t help me a lot.

Basically I have two questions.

1).Is the variable "Field" holds an object in base64, if so, what should be the type? Memo?

2) If it is a table of data lines having two key fields LineNum and DocEntry whether the following code is correct.


            BlobTableKeySegment seg = param.BlobTableKeySegments.Add();
            seg.Name = "DocEntry";
            seg.Value = "1";
            BlobTableKeySegment seg2 = param.BlobTableKeySegments.Add();
            seg2.Name = "LineNum";
            seg2.Value = "1";

Thanks for quick reply