Monday, July 14, 2014

Getting file content of a record from document handling and return to device / base64 code

public notes ArchiveBlob(str strFilePath="C:\\Users\\hemamalinib\\Downloads\\T&L-TDD-V1.2.docx")
{
    Set permissionSet;
    //Hold the instance of table....
//    docuValue objdocuRef;
    //This class is used to process the blob data....
    BinData bin = new BinData();

    //Hold the instance of the encoded string format...

   System.IO.FileStream outFile;
   System.Byte[] arrByte;
   str content;
   System.Int32 j;
   container temp;
    ;
    // Assert permission.
    permissionSet =  new Set(Types::Class);
    permissionSet.add(new FileIOPermission(strFilePath ,"rw"));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
   //FileIOPermission fioPermission;
   //InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
   //permission.assert();
    //getting file
   //objdocuRef= docuValue::find(_valueRecId); //5637145107);

// Assert permission.
    //fioPermission = new FileIOPermission(strFilePath ,"RW");
    //fioPermission.assert();

    //arrByte= System.IO.File::ReadAllBytes(strFilePath);

    //content =System.Convert::ToBase64String(arrByte);
     //  j =  outFile.Read(arrByte, 0,outFile.
    //CodeAccessPermission::revertAssert();


    //return content;
    // outFile.Close();
  //creating BinData object from Container in the CompanyImage object
    //bin.setData(objdocuRef.File);

    CodeAccessPermission::assertMultiple(permissionSet);
    //temp = this.Job_File_IO_TextIo_Write_Read(strFilePath);
    content = this.Job_File_IO_TextIo_Write_Read(strFilePath);//con2str(temp);
    //temp = WINAPI::findFirstFile(strFilePath);
    //bin.setData(temp);
    //bin.setData(tobjdocuRef.File);
    //encoding the image to base64
    //content = bin.base64Encode();
    // Create the base64 encoded string

    //This is for testing purpose
    //arrByte =System.Convert::FromBase64String(content);
    //outFile = new System.IO.FileStream(strFilePath,System.IO.FileMode::Create,
                             //System.IO.FileAccess::Read);
    //outFile.Read(arrByte, 0, arrByte.get_Length());
    //outFile.Close();
    return content;
}

using the above method
------------------------
//getting file content and return to device
notes filedet;
   filedet = AIF_DOCHandCustomService_add.ArchiveBlob(file);


Another Way
-------------
public notes Blob(RefRecId _valueRecId)
{
    //Hold the instance of table....
    docuValue objdocuRef;
    //This class is used to process the blob data....
    BinData bin = new BinData();
    //Hold the instance of the encoded string format...
    str content;
   System.IO.FileStream outFile;
   System.Byte[] arrByte;
    //getting file
   objdocuRef= docuValue::find(_valueRecId); //5637145107);

  //creating BinData object from Container in the CompanyImage object
    bin.setData(objdocuRef.File);
    //encoding the image to base64
    content = bin.base64Encode();
    // Create the base64 encoded string
    /*
    //This is for testing purpose
    arrByte =System.Convert::FromBase64String(content);
      outFile = new System.IO.FileStream(@"D:\DocHandling\test1.docx",System.IO.FileMode::Create,
                                 System.IO.FileAccess::Write);
      outFile.Write(arrByte, 0, arrByte.get_Length());
      outFile.Close();
    */
    return content;
}

No comments:

Post a Comment