c# 4.0 - Crystal Reports 8.5 Sections prevents file from being deleted in C# using COM -
i have created command line application takes crystal report file, opens it, exports text file , cleans after deleting crystal report. works fine until suppress sections in crystal report, when try , delete following:
system.io.ioexception: process cannot access file 'c:\exportcmd\bin\debug\reportexport\2ee373f0-e05a-42d6-9b61-9c79e2662c20\14_636271819978854269.rpt' because being used process.
after investigation have found happens when suppress section in open report, if comment out code works fine. code setting suppress flag is:
private static void suppressreportsection(ref report openreport, string sectiontofind, bool hidesection) { if (!string.isnullorwhitespace(sectiontofind) && openreport != null) { openreport.sections[sectiontofind].suppress = hidesection; } }
after checking google solution, gave following try:
private static void suppressreportsection(ref report openreport, string sectiontofind, bool hidesection) { if (!string.isnullorwhitespace(sectiontofind) && openreport != null) { sections reportsections = openreport.sections; try { if (reportsections != null) { reportsections[sectiontofind].suppress = hidesection; } } catch { throw; } { if (reportsections != null) { marshal.releasecomobject(reportsections); reportsections = null; } } } }
this unfortunately didn't cure either. have tried , without ref in case report object.
i having use crystal reports 8.5, , have added reference. when destroy report object call marshal.releasecomobject, gc.waitforfullgccomplete() in hope have released file. once has completed call cleanup code deletes files. clean method allow multiple attempts @ deleting file before throws error.
where going wrong? if there answer question can point me please.
i using c# .net 4 highest version can on servers. can't use crystaldecisions assemblies.
try use finalreleasecomobject instead:
therefore, use releasecomobject if absolutely required. if want call method ensure com component released @ determined time, consider using finalreleasecomobject method instead. finalreleasecomobject release underlying com component regardless of how many times has re-entered clr. internal reference count of rcw incremented 1 every time com component re-enters clr. therefore, call releasecomobject method in loop until value returned zero. achieves same result finalreleasecomobject method.
Comments
Post a Comment