Skip to main content
Nintex Community Menu Bar

Custom ServiceObject Question - SoType.File?????

  • November 20, 2007
  • 2 replies
  • 27 views

Forum|alt.badge.img+1

Hi,

I've followed Jason Apergis's excellent blog post on creating cutom SmartObject Services (found here).

In my service I want the ServiceObject to have a property of type File, but I can't seem to figure out which Type to use for the value. Here's what I've got:

            Property propData = new Property();
            propData.Name = "FileData";
            propData.MetaData.DisplayName = "FileData";
            propData.MetaData.Description = "File Data";
            propData.Type = "System.IO.MemoryStream";
            propData.SoType = SoType.File;
            so.Properties.Add(propData);

With the Type set to System.IO.MemoryStream, it throws an exception stating "Timeouts are not supported on this stream".

I've tried byte[] and System.Object, but it throws this exception:
[FormatException: Data format for SmartFileProperty type incorrect. [FileData]]
SourceCode.SmartObjects.Client.SmartFileProperty.GetRuntimeData(String value) +550 

Does anyone know how exactly to use a ServiceObject Property of type SoType.File?

Thanks.

 

2 replies

Forum|alt.badge.img+7
  • November 21, 2007
Did you try System.IO.FileStream?

Forum|alt.badge.img+1
  • Author
  • November 21, 2007

OK, I think I figured this out.

Checking the class model for the SourceCode.SmartObjects.Services.ServiceSDK.Objects namespace I saw a FileProperty type. Use this declaration (make sure to use this constructor - see why with reflection):

            FileProperty fpropData = new FileProperty("FileData", new MetaData(), String.Empty, String.Empty);
            fpropData.MetaData.DisplayName = "File Data";
            fpropData.MetaData.Description = "File Data";
            this.Properties.Add(fpropData);

When it comes to assigning a value to ServiceBroker.ServicePackage.ResultTable.NewRow Item (during a Read/List operation), you have to encode your byte[] file content as Base64 and enclose it in XML.

I used this helper method to simplify the process:

        public static object ToFilePropertyValue(string propName, string filename, byte[] content)
        {
            return (new FileProperty(propName, new MetaData(), filename, Convert.ToBase64String(content))).Value;
        }

So the assignment operation looks like this: 

        dr["File"] = Helper.ToFilePropertyValue("File", "foobar.dat", {foobar byte[]});

It seems that Smart Object File properties hold the name and Base64 encoded content of the file. So, if in your process you need to store the content locally (at process level or activity level), use a String field.

Huge thanks goes out the mighty Lutz Roeder's .NET reflector. 

R