Loading ...

How Pagesource In Acumatica Works

Hello everybody,

recently I was asked by one friends of mine, how pageSource in Acumatica works, i.e. how to code/decode pagesource contents. 

After different methods of trial and error I've created following C# code in order to code/decode pageSource:

Snippet

private static string Compress(string src)
        {
            if (src.IsNullOrEmpty())
            {
                return null;
            }
            byte[] bytes = Encoding.UTF8.GetBytes(src);
            using (MemoryStream stream = new MemoryStream())
            {
                using (DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Compress))
                {
                    stream2.Write(bytes, 0, bytes.Length);
                }
                return Convert.ToBase64String(stream.ToArray());
            }
        }
 
        private static string Decompress(string compressed)
        {
            string str;
            if (compressed.IsNullOrEmpty())
            {
                return null;
            }
            using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(compressed)))
            {
                using (DeflateStream stream2 = new DeflateStream(stream, CompressionMode.Decompress))
                {
                    using (StreamReader reader = new StreamReader(stream2))
                    {
                        str = reader.ReadToEnd();
                    }
                }
            }
            return str;
        }

 

With help of that code you can analyze content of page in customization and modify it according to your needs.