File is distorted while uploading binary data from C# on SAP

15 views
Skip to first unread message

Sana Rajput

unread,
Nov 26, 2018, 4:42:22 AM11/26/18
to QTP - HP Quick Test Professional - Automated Software Testing

File when convert into bytes and passing to RFC without any issue but when trying to open file at SAP its does not opening or it seems to be corrupted. Please provide me any solution what went wrong, below is my code:

IRfcTable BINARCHIVOBJECT_TBL = IT_ATTACHMENTS_STRUC.GetTable(RFC_Constant.BINARCHIVOBJECT);
                    RfcStructureMetadata BINARCHIVOBJECT_MetaDataAtt = BINARCHIVOBJECT_TBL.Metadata.LineType;
                    IRfcStructure BINARCHIVOBJECT_STRUC = null;
                    
                    //List<byte> bytes = new List<byte>();
                    #region - Split file byte by 1024 -
                    List<byte[]> arrList = splitArray2(objLicenseAndCertificateDocument.File, 1024);
 
                    int BinaryLength = 0;
                    foreach (byte[] b in arrList)
                    {
                        BINARCHIVOBJECT_STRUC = BINARCHIVOBJECT_MetaDataAtt.CreateStructure();
                        BINARCHIVOBJECT_STRUC.SetValue("LINE", b);
                        BINARCHIVOBJECT_TBL.Append(BINARCHIVOBJECT_STRUC);
                        BinaryLength += 1;

                        //bytes.AddRange(b.ToList());
                    }

For Split array into size of 1024

 private List<byte[]> splitArray2(byte[] barray, int splitSize)
        {
            var bList = new List<byte[]>();
            byte[] dest = new byte[splitSize];
            for (int i = 0; i < barray.Length; i += splitSize)
            {
                if (barray.Length - i >= 1024)
                {
                    Array.Copy(barray, i, dest, 0, splitSize);
                }
                else
                {
                    dest = new byte[barray.Length - i];
                    Array.Copy(barray, i, dest, 0, barray.Length - i);
                }
                bList.Add(dest);
                dest.Initialize();
            }
            return bList;
        }
Reply all
Reply to author
Forward
0 new messages