Re: Attachment Using CDO.MESSAGE
am 23.12.2007 07:31:13 von rn5aOn Dec 22, 6:08=A0pm, "Anthony Jones"
> "RN1"
>
> news:22c8c699-74bf-4525-8332-a7851d885a8f@d27g2000prf.google groups.com...
>
>
>
>
>
> > On Dec 15, 5:34 pm, "Anthony Jones"
> > > "RN1"
>
> > >news:53695732-6bf3-48ad-9045-79d4a0c0b38b@t1g2000pra.google groups.com..=
..
>
> > > > An ASP page first creates a MS-Word (doc) document using the values
> > > > received from a HTML Form & then mails this doc file as an attachmen=
t
> > > > for which I am using CDO.MESSAGE but the line
>
> > > > cdoMessage.AddAttachment Server.MapPath(strFile)
>
> > > > generates the following error:
>
> > > > The process cannot access the file because it is being used by anoth=
er
> > > > process.
>
> > > > which points to the AddAttachment line (shown above).
>
> > > > How do I overcome this error?
>
> > > You'll have a Word application object still holding the file open. =A0=
As
> the
> > > link that Bob has posted in a later thread indicates, this not a good
> idea.
>
> > > --
> > > Anthony Jones - MVP ASP/ASP.NET
>
> > Anthony, if I am not mistaken, what Bob has suggested is very much
> > different to what I want to do here. What Bob has suggested that is
> > for opening a Word file using ASP but here I want to first create the
> > Word document (which I have taken care of) & then mail it as an
> > attachment. At no point do I want to open that Word document that ASP
> > creates.
>
> Please post the code that creates the Word document.
>
>
>
> > Anyway, how do I ensure that the Word object is not holding the file
> > open?
>
> My advice is don't use Office objects in ASP.
>
> --
> Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
>
> - Show quoted text -
Here is the code that creates the Word document Anthony:
==================== =====3D=
=============3D
<%
Dim strParty,strNewFile,strFolderPath
strParty=3DRequest.Form(strParty)
strNewFile=3D"LETTERS\Letter" & Replace(strParty," ","") & ".doc"
strFolderPath=3D"LETTERS"
Dim objFSO,objFolder,objFile
Set objFSO=3DServer.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set objFolder=3DobjFSO.GetFolder(Server.MapPath(strFolderPath))
Const ForAppending=3D8
Const ForWriting=3D2
If Not(objFSO.FileExists(Server.MapPath(strNewFile))) Then
Set objFile=3DobjFSO.CreateTextFile(Server.MapPath(strNewFile))
Else
Set
objFile=3DobjFSO.OpenTextFile(Server.MapPath(strNewFile),For Writing)
End If
objFile.WriteLine("............")
objFile.WriteLine("............")
objFile.WriteLine("............")
'e-mail code using CDO.MESSAGE to send
'the DOC file as an attachment comes here
'deleting the DOC document after 5 hours
For Each objFile In objFolder.Files
If(InStr(objFile.Name,".doc")>0) Then
If(DateDiff("n",objFile.DateLastModified,Now())>300) Then
objFile.Delete
End If
End If
Next
Set objFile=3DNothing
Set objFSO=3DNothing
==================== =====3D=
=============3D
>> My advice is don't use Office objects in ASP
Then how does one send Office documents as attachments in ASP?
Thanks,
Ron