Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
How do I decode a layout byte array without loading it into a gird?
posted

I save layouts to a stream using:

  grid.DisplayLayout.Save(stream, flags);

which I save to the database as a byte array.

Then, when I want to load the layout, I use:

  grid.DisplayLayout.Load(stream);

So far so good.

The problem I am having is that I need to know what columns a user has displayed, but without loading the layout into a grid (basically business logic related to visible grid columns is in an area of the application that does not have a grid displayed, not does it make sense to display one).

When I try to decode the layout byte stream:

  Encoding.Default.GetString(layoutByteArray);

The data is not easy to decipher, below is a snippet:



I notice that it contains null terminators, control codes, and other odd characters.

Is there a way to decode this?

Parents
No Data
Reply
  • 22852
    Offline posted

    The best approach if you need to be able to parse the layout is to use the SaveAsXml and LoadFromXml methods to load and save the layout as you can actually parse the XML.

    For the binary content, it would be best to deserialize it back to an UltraGridLayout to read the column information.  For persistence of binary layouts, we use the BinaryFormatter  with AssemblyFormat set to Simple to save and load the layout internally.  If you want to see more details on how this is done it would be best to download our source code review that to see if there is logic that you could use.

    Assuming that the reason for not wanting to load a grid in your business logic is because the grid assembly isn't referenced, then deserializing the binary object may not be a viable option.  The stackoverflow question: Convert from binary to XML serialization without needing the type doesn't appear to have a solution.

    Another alternative is to also read the column information on your own from the grid when serializing the layout and also serialize the column information on your own in a format that you can read in your business logic.

    Let me know if you have any questions

Children