static void WriteCheckSideImageToDisk(X9DepositItemImage image, DirectoryInfo destDir, string fileName, string virtualRunPath) { string absPath = Path.Combine(destDir.FullName, fileName); X9ImageField imageField = image.ImageViewData.ImageData; if (File.Exists(absPath)) { File.Delete(absPath); } byte[] imageData = imageField.GetImageBytes(); if (imageData != null && imageData.Any()) { using (var imageBytes = new MemoryStream(imageData)) using (var outFile = File.OpenWrite(absPath)) { imageBytes.CopyTo(outFile); } if (virtualRunPath != null) { Uri runRelativeUri = new Uri(StandardPaths.CombinePaths(virtualRunPath, destDir.Name, fileName), UriKind.Relative); imageField.Image = FileReference.Create(absPath, runRelativeUri); } } else { throw new ArgumentNullException("Could not write image bytes to disk because none were found."); } }