vb.net - The process cannot access the file '*.doc' because it is being used by another process -


i have number of files created, saved, printed , deleted. don't open them. last file deleted held process can not deleted.

this error message:

the process cannot access file 'c:\temp\34_temp.doc' because being used process.

this save file. use third party control (spire .doc .net) create document. closed after saved.

 dim tfname string = my.application.info.directorypath & "\" & now.tostring("hhmmss") & g.tostring() & "_temp.doc"  orderdetailsdoc.savetofile(tfname, spire.doc.fileformat.doc)  orderdetailsdoc.close()  sendmetoprint(tfname)  orderdetailsdoc = nothing 

this print procedure:

 public sub sendmetoprint(byval tmpfilename string)     const cssubname string = "sendmetoprint"      on error goto errorhandler      using dialog new printdialog()         dim d new spire.doc.document(tmpfilename)         d.printdialog = dialog         dialog.document = d.printdocument          dialog.allowcurrentpage = true         dialog.allowsomepages = true         dialog.useexdialog = false         dialog.printtofile = false          dialog.document.print()         d.close()         d.printdocument.dispose()         d = nothing      end using      end sub 

this use delete files. thread sleep doesn't help. hoping give process time release file, doesn't. appreciated.

public sub clearfolder(byval dirstring string)      dim foundfile string     dim integer      each foundfile in my.computer.filesystem.getfiles(dirstring, fileio.searchoption.searchtoplevelonly, "*temp.doc")         if my.computer.filesystem.fileexists(foundfile)             = 1 10                 try                     my.computer.filesystem.deletefile(foundfile)                     exit                 catch ex exception                     if = 10                         logit(now.tostring("mm/dd/yyyy hh:mm:ss tt") & "  " & cssubname)                         logit(now.tostring("mm/dd/yyyy hh:mm:ss tt") & "  unable delete file " & foundfile & " after 10 tries on 10 seconds.")                         logit(now.tostring("mm/dd/yyyy hh:mm:ss tt") & "  exception says: " & ex.message)                     else                         threading.thread.sleep(1000)                     end if                 end try             next         end if     next      exit sub  end sub 

this sub called print multiple orders. screen contains listing of orders printed.

a loop through each order order detail necessary:

public sub printallorders(optional byval printbatchnum integer = 0)      const cssubname string = "printallorders"     on error goto errorhandler      dim objprintpick clspickscreen     dim argworkobject clsworkorder     dim strerrorlocation string = ""     dim pbn integer     dim g integer = 0     dim rsbatchreprint adodb.recordset     dim orderdetailsdoc new spire.doc.document      frmpickscreen.pickprint = true          pbn = generateprtbatchnum()         strerrorlocation = "just generated print batch number"          each objprintpick in objtotalpickscreen              blnredprint = objprintpick.alreadyprinted              if objprintpick.printed = false                  objprintpick.printed = true                 g = g + 1                  argworkobject = new clsworkorder                 argworkobject.connection = consqldatabase                  argworkobject.userid = gstruserid                 argworkobject.role = gconpicking_role                 argworkobject.orderid = objprintpick.orderid                 argworkobject.suborderid = objprintpick.suborderid                 argworkobject.suborderpickscrnstatus = cshort(objprintpick.status)                 argworkobject.storenumber = objprintpick.fulfillstore                 argworkobject.loadworkorder()                 argworkobject.printbatchnumber = pbn                   call spireprintorder(argworkobject, (gobjoptions.printmulticopies), orderdetailsdoc)                 insertnewpage(orderdetailsdoc)               end if               if g mod 10 = 0 , g > 0                  dim tfname string = my.application.info.directorypath & "\" & now.tostring("hhmmss") & g.tostring() & "_temp.doc"                 orderdetailsdoc.savetofile(tfname, spire.doc.fileformat.doc)                 orderdetailsdoc.close()                 sendmetoprint(tfname)                 'system.diagnostics.process.start(tfname)                  orderdetailsdoc = nothing                 orderdetailsdoc = new spire.doc.document             end if          next objprintpick           if g = 0             msgbox("there no unprinted orders.")             frmpickscreen.cmdprintdialog.printersettings.copies = 1             frmpickscreen.cmdprintdialog.printersettings.defaultpagesettings.landscape = false         else              strerrorlocation = "about send order printer - outside loop"             dim tfname string = my.application.info.directorypath & "\" & now.tostring("hhmmss") & g.tostring() & "_temp.doc"             orderdetailsdoc.savetofile(tfname, spire.doc.fileformat.doc)             orderdetailsdoc.close()             sendmetoprint(tfname)             orderdetailsdoc = nothing             'system.diagnostics.process.start(tfname)         end if  end sub   public sub spireprintorder(byref argworkobject clsworkorder, byref argblnprintmultiple boolean, byref orderdetailsdoc document)      dim intpagenum integer     dim intlinesprinted integer     dim strerrorlocation string     dim x integer     dim blnspecitem boolean     dim integer     dim g integer     dim lngcountofdepts integer     dim strprintdate string     dim strdescprint string = ""     dim boolpickprint boolean = frmpickscreen.pickprint     dim prodpara paragraph     dim tmpsec section      on error goto errorhandler      dim dialog new printdialog()     dialog.allowcurrentpage = true     dialog.allowsomepages = true     dialog.useexdialog = true      strerrorlocation = "preparing print printorder"     lngcountofdepts = 0     strprintdate = cstr(now)      dialog = frmpickscreen.cmdprintdialog     intnumcopies = dialog.printersettings.copies     lngcountofdepts = getnumberofdepts((argworkobject.suborderid), (argworkobject.storenumber))           g = 1 lngcountofdepts              if g > 1                 insertnewpage(orderdetailsdoc)             end if              = 1 intnumcopies                  logit(now.tostring("mm/dd/yy hh:mm:ss") & "  number of copies " & intnumcopies.tostring())                 intpagenum = 1                 ipagelinecounter = 0                   spirepageheader(orderdetailsdoc, argworkobject, intpagenum, true, false, argblnprintmultiple, g, lngcountofdepts, strprintdate)                 spirestaticheader(orderdetailsdoc)                    x = 1 argworkobject.allorderitems.count                     if ipagelinecounter > 35                         intpagenum += 1                          insertnewpage(orderdetailsdoc)                         ipagelinecounter = 0                          spirepageheader(orderdetailsdoc, argworkobject, intpagenum, true, false, argblnprintmultiple, g, lngcountofdepts, strprintdate)                         spirestaticheader(orderdetailsdoc)                      end if                      blnspecitem = false                      if argworkobject.allorderitems.item(x).isgiftwrap = true or argworkobject.allorderitems.item(x).mfgrebate = true                         blnspecitem = true                     end if                      strdescprint = trim(left(argworkobject.allorderitems.item(x).itemdescription, 65))                     if blnspecitem = true                         strdescprint = "(spc item) " & left(strdescprint, 54)                     end if                      if blnredprint = true                         if argworkobject.allorderitems.item(x).printed = false                             strdescprint = "(new item) " & trim(left(strdescprint, 54))                         end if                     end if          'pad fields displayed on page astetic appearance                     padproduct(argworkobject, x)                     addorderdata(argworkobject.allorderitems.item(x).imagepathname, orderdetailsdoc, strdescprint)                     if argworkobject.allorderitems.item(x).mfgrebate = true                          tmpsec = orderdetailsdoc.sections.lastitem                         prodpara = tmpsec.paragraphs(0)                         prodpara.appendtext(space(5) & argworkobject.allorderitems.item(x).mfgrebatemsg & vbcrlf).characterformat.font = mycnreg12font                         prodpara.appendtext("---------------------------------------------------------------------------------------------------------------" & vbcrlf).characterformat.font = mycnreg12font                         ipagelinecounter += 2                     end if                  next                   if ucase(trim(argworkobject.shippingmethod)) = "ups expedited"                      if ipagelinecounter > 35                          spirepageheader(orderdetailsdoc, argworkobject, intpagenum, true, false, argblnprintmultiple, g, lngcountofdepts, strprintdate)                      end if                      tmpsec = orderdetailsdoc.sections.lastitem                     prodpara = tmpsec.paragraphs(0)                     prodpara.appendtext("  " & vbcrlf)                     prodpara.appendtext("  " & vbcrlf)                     prodpara.appendtext(space(31) & "***************************************************" & vbcrlf).characterformat.font = mycnbold12font                     prodpara.appendtext(space(31) & "*  customer paying premium rush service  *" & vbcrlf).characterformat.font = mycnbold12font                     prodpara.appendtext(space(31) & "*       please prioritize picking & packing       *" & vbcrlf).characterformat.font = mycnbold12font                     prodpara.appendtext(space(31) & "*             ship ups second day air             *" & vbcrlf).characterformat.font = mycnbold12font                     prodpara.appendtext(space(31) & "***************************************************" & vbcrlf).characterformat.font = mycnbold12font                  end if                  if argworkobject.comments.commentsexist = true                      call sprirecomments(orderdetailsdoc, argworkobject, intpagenum, ipagelinecounter, argblnprintmultiple, g, lngcountofdepts, strprintdate)                  end if              next          next  end sub 


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -