Nate1
03-25-2008, 05:56 PM
I have built this sub to retrieve information off an email form and place it into a number of different email templates, this works well, though the sub in question creates a temp file (not actual temp directory - kept saying used by another process?) I have to use response.end else the response serves the entire web page not just the email.htm preview. How can I delete this temp file, so I can then use a unique ID to make sure two users don't have conflicts?
Dim FileName As String = Server.MapPath(Utility.AppSettings.TemplateFolderPath & "fil.tmp")
Dim f As New FileInfo(ToText(Utility.AppSettings.TemplateFolderPath & ddlEmailTemplates.SelectedValue))
Dim e As TemplateEmail = getTemplateInformation()
Dim info As String = ParseEmailTemplate(e, Server.MapPath(Utility.AppSettings.TemplateFolderPath) & ddlEmailTemplates.SelectedValue)
Dim fs As New FileStream(FileName, FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.WriteLine(info)
s.Close()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Email_Preview" & f.Extension & "l")
Try
HttpContext.Current.Response.WriteFile(FileName)
Finally
'Dim delfile As New FileInfo(FileName)
'delfile.Delete()
Response.End()
End Try
'Then Delete the File
Dim FileName As String = Server.MapPath(Utility.AppSettings.TemplateFolderPath & "fil.tmp")
Dim f As New FileInfo(ToText(Utility.AppSettings.TemplateFolderPath & ddlEmailTemplates.SelectedValue))
Dim e As TemplateEmail = getTemplateInformation()
Dim info As String = ParseEmailTemplate(e, Server.MapPath(Utility.AppSettings.TemplateFolderPath) & ddlEmailTemplates.SelectedValue)
Dim fs As New FileStream(FileName, FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
s.WriteLine(info)
s.Close()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/octet-stream"
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Email_Preview" & f.Extension & "l")
Try
HttpContext.Current.Response.WriteFile(FileName)
Finally
'Dim delfile As New FileInfo(FileName)
'delfile.Delete()
Response.End()
End Try
'Then Delete the File