//called just after GetValue(). public void SaveValue() { //to prevent decoding to fail if (!string.IsNullOrWhiteSpace(encodedstring)) { int mod4 = encodedstring.Length % 4; if (mod4 > 0) { encodedstring += new string('=', 4 - mod4); } try { byte[] bytes = Convert.FromBase64String(encodedstring); if (bytes != null) { IFileRepository repo = new FileRepository(); repo.SaveMedia(filename, bytes); if (!string.IsNullOrWhiteSpace(_context.OldValue)) { repo.DeleteMedia(_context.OldValue); } } } catch (FormatException) { } catch (ArgumentNullException) { } } }