Our product uses a Web Browser Control to import local files directly into our web app. When a user clicks "Import" on the software, selected files are saved to a temp file then the Web Browser Control opens to our web app where the files are imported. From there the user can edit properties in the web app.
This works fine with smaller files but once files reach about 10MB and higher an OutOfMemory Exception is thrown.
Here is a simplification of the code we use to retrieve and pass files to the web app:
public string GetFiles() {
List<DmFile> dmFiles = new List<DmFile>(); // DmFile is a class containing the file bytes and other document information
foreach (var file in ImportFiles) { // ImportFiles contains the list of class ImportFile
byte[] fileBytes = File.ReadAllBytes(file.FilePath);
DmFile dmFile = new DmFile(file.Name, fileBytes);
dmFiles.Add(dmFile);
}
string jsonList = JsonConvert.SerializeObject(dmFiles);
return jsonList;
}
GetFiles() serializes the file list and passes the JSON to the view model.
Here is a snippet of the view model (javascript) code:
var webControl: any = window.external;
var jsonFilesString = webControl.GetFiles();
We call the Web Browser Control using window.external
. Then we call the GetFiles()
method directly from the Javascript code to retrieve the JSON so we can use the file bytes.
The OutOfMemory exception occurs after GetFiles()
when it attempts to set the JSON to the jsonFilesString
.
Any idea on where we can optimize to allow for these larger file sizes or is this a limitation on our method of file transfer (passing JSON through WebBrowserControl)?
Thanks