Problem with the File Attachment control

  • 28 September 2015
  • 2 replies
  • 101 views

Badge +3

Hello,

In my process I recieve a pdf file via a web service. The file is sent as byte array and I store it in a binary data field. I tried to convert it to a string and send it as the following string : <file><name>some_name.pdf></name><content>string_content</content></file> to the file attachment control that I have on my smartform but it doesn't work. The file is shown as a string and if I click on the control nothing happens.

I also tried using the expression Get File From content.
What can I do? I know the type (string) of the datafield is the problem.

Thank you in advance,
Veronika

Edit: I also tried sending an xml field to the file attachment control but no use. Is there a way to convert the string data field to File type before sending it to the File attachment control?


2 replies

Badge +5

Hi,

 

I assume that you convert the binary to base64 string.

 

As far as I understand, if the SmartObject you are using is drawing the base64 string column value, you just need to ensure that the corresponding SmartObject property's type is set to "File" will do.

 

 

 

JK.


Badge +4

Hi,

I was doing the same and I had faced the same issue. 

 

 

string fileDetails = "<file><name>{0}</name><content>{1}</content></file>";

string myString;

using (BinaryReader br = new BinaryReader(fileUpload1.PostedFile.InputStream))
{
      byte[] bin = br.ReadBytes(Convert.ToInt32(fileUpload1.PostedFile.InputStream.Length));
      myString = Convert.ToBase64String(bin);
}

 

 // This code is working fine for myTable table that is a custom table

CustomDB_MyDB_dbo_MyTable svcFileObj = new CustomDB_MyDB_dbo_MyTable();
svcFileObj.Data = string.Format(fileDetails, fileUpload1.FileName, myString.ToString()); // Data is a nvarchar(max) field
svcFileObj.Extension = ".txt";
svcFileObj.Name = fileUpload1.FileName;

CustomDB_MyDB_dbo_MyTableSvcClient svcFileObj = new CustomDB_MyDB_dbo_MyTableSvcClient();
svcFileObj.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

svcFileObj.CustomDB_MyDB_dbo_MyTableSvc_Create(svcFileObj);

Regards,

Asad Naeem

Reply