Can't delete after filing and saving

using this code i get "access denied" when i try to delete the docment file.

IO.File.Delete(out)

i added code to create and delete a file in the \temp folder to show it's no a permission problem. it seems like aspsose hold the doc/object open. i want to delete the output afer creatation.

Thanks, Tack

Dim tmp As String = IO.Path.GetTempFileName

Dim out As String

out = IO.Path.Combine(settings.tmpFolder, settings.SessionID & ".doc")

IO.File.Copy(settings.LienSettlementForm, out)

Dim license As Aspose.Words.License = New Aspose.Words.License()

license.SetLicense("Aspose.Words.lic")

Dim settleDoc As Aspose.Words.Document = New Aspose.Words.Document(out)

settleDoc.Range.Bookmarks("Date").Text = dated.ToShortDateString

settleDoc.Range.Bookmarks("Attn").Text = name

settleDoc.Range.Bookmarks("CoName").Text = caseRecs.CusNameFirm

settleDoc.Range.Bookmarks("Fax").Text = caseRecs.Customer.Fax

settleDoc.Range.Bookmarks("phone").Text = caseRecs.Customer.Phone

settleDoc.Range.Bookmarks("AppName").Text = caseRecs.Order.Name

settleDoc.Range.Bookmarks("Defendant").Text = caseRecs.Order.Defendant

settleDoc.Range.Bookmarks("ClaimNum").Text = caseRecs.Order.ClaimNum

settleDoc.Range.Bookmarks("OrderNum").Text = caseRecs.OrderNum.ToString

settleDoc.Range.Bookmarks("Dear").Text = name

settleDoc.Range.Bookmarks("Totaling").Text = caseRecs.Ledger.TotalInvoices.ToString("$#,##0.00")

settleDoc.Range.Bookmarks("Amount").Text = amount.ToString("$#,##0.00")

settleDoc.Range.Bookmarks("Today").Text = DateTime.Today.ToShortDateString

settleDoc.Save(out, Aspose.Words.SaveFormat.Doc)

Dim smtp As Net.Mail.SmtpClient = Nothing

Dim mmsg As Net.Mail.MailMessage = Nothing

mmsg = New Net.Mail.MailMessage

mmsg.From = New Net.Mail.MailAddress(_From)

Dim tos() As String = _to.Split(New Char() {","c, ";"c})

For Each [to] As String In tos

mmsg.To.Add(New Net.Mail.MailAddress([to]))

Next

If _cc IsNot Nothing Then

Dim ccs() As String = _cc.Split(New Char() {","c, ";"c})

For Each [cc] As String In ccs

mmsg.CC.Add(New Net.Mail.MailAddress([cc]))

Next

End If

If _bcc IsNot Nothing Then

Dim bccs() As String = _bcc.Split(New Char() {","c, ";"c})

For Each [bcc] As String In bccs

mmsg.Bcc.Add(New Net.Mail.MailAddress([bcc]))

Next

End If

mmsg.Subject = String.Format("Zing Settlement for {0}", caseRecs.OrderNum.ToString)

mmsg.Body = "see attached"

mmsg.IsBodyHtml = True

mmsg.Attachments.Add(New Net.Mail.Attachment(out))

smtp = New Net.Mail.SmtpClient(settings.SMTPServer)

smtp.Send(mmsg)

settleDoc = Nothing

If IO.File.Exists(tmp) Then

IO.File.Delete(tmp)

End If

If IO.File.Exists(out) Then

IO.File.Delete(out)

End If

Hi Tack,

Thanks for your inquiry.

Aspose.Words releases the file straight after loading it into a new Document object. I don't think it would be Aspose.Words which is causing this error.

In your code you aren't referencing the temporary folder, instead you are still using settings.tmpFolder. Could you try using the tmp folder and see if this helps? Also you are copying an existing file and working off that, could you try creating a new file (you can do this by using Document doc = new Document() in the mean time and see if this helps).

If the issue still occurs could you please create a sample project which demostrates issue that can be used to test on my side.

Thanks,

wow, thanks for the quick response. you are right, it’s not aspose holding it open.

Hi Tack,

It's great the issue is resolved. If you have any further queries, please feel free to ask.

Thanks,