Why DocIO doesn't dispose loaded picture in .NET WebForms?
In our older versions of Essential® studio® (before 10.3.0.53) we have preserved System.Drawing.Image instance as a reference in WPicture and PictureWatermark. So it is necessary to dispose the System.Drawing.Image instance preserved in the WPicture object before deleting the image file. Whereas in later versions (from 10.3.0.53) we have optimized the main memory utilization by preserving single reference of an image for the entire document as image bytes instead of System.Drawing.Image instance. Kindly dispose the System.Drawing.Image instance explicitly before trying to delete the image file in later versions.
Below code snippets demonstrates how to delete the image file after setting it as picture watermark in Word documents.
C#:
PictureWatermark watermark = new PictureWatermark(); //Gets the image file FileInfo imageFile = new FileInfo(imagePath); //Loads image from file system Image image = Image.FromFile(imagePath); //Sets the image to the PictureWatermark watermark.Picture = image; document.Watermark = watermark; //Dispose the image image.Dispose(); //Delete the image file imageFile.Delete();
VB:
Dim watermark As New PictureWatermark() ‘Gets the image file Dim imageFile As New FileInfo(imagePath) ‘Loads image from file system Dim image As Image = Image.FromFile(imagePath) ‘Sets the image to the PictureWatermark watermark.Picture = image document.Watermark = watermark ‘Dispose the image image.Dispose() ‘Delete the image file imageFile.Delete();
Below code snippets demonstrates how to delete the image file after loading it as picture in Word documents.
C#:
//Gets image file FileInfo imageFile = new FileInfo(imagePath); //Loads image from file system Image image = Image.FromFile(imagePath); //Appends picture to the paragraph IWPicture picture = paragraph.AppendPicture(image); //Dispose the image image.Dispose(); //Delete the image file imageFile.Delete();
VB:
Dim watermark As New PictureWatermark() ‘Get image file Dim imageFile As New FileInfo(imagePath) ‘Loads image from file system Dim image As Image = Image.FromFile(imagePath) ‘Appends picture to the paragraph Dim picture As IWPicture = paragraph.AppendPicture(image); ‘Dispose the image image.Dispose() ‘Delete the image file imageFile.Delete();
Note:
A new version of Essential® Studio® for ASP.NET is available. Versions prior to the release of Essential® Studio® 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential® Studio® for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.
The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential® Studio® for ASP.NET. Although Syncfusion® will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.
You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!