Re: Attachment Using CDO.MESSAGE

Re: Attachment Using CDO.MESSAGE

am 23.12.2007 15:33:01 von rn5a

On Dec 23, 6:12=A0pm, "Anthony Jones" wrote:
> "RN1" wrote in message
>
> news:2164bba1-97c6-408b-a59e-c31132e18e7f@i29g2000prf.google groups.com...
> On Dec 22, 6:08 pm, "Anthony Jones" wrote:
>
>
>
>
>
> > "RN1" wrote in message
>
> >news:22c8c699-74bf-4525-8332-a7851d885a8f@d27g2000prf.googl egroups.com...=

>
> > > On Dec 15, 5:34 pm, "Anthony Jones" wrote:
> > > > "RN1" wrote in message
>
> >news:53695732-6bf3-48ad-9045-79d4a0c0b38b@t1g2000pra.google groups.com...
>
> > > > > An ASP page first creates a MS-Word (doc) document using the value=
s
> > > > > received from a HTML Form & then mails this doc file as an
> attachment
> > > > > 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
> another
> > > > > 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. A=
s
> > the
> > > > link that Bob has posted in a later thread indicates, this not a goo=
d
> > 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:
>
> <%
> =A0 =A0 Dim strParty,strNewFile,strFolderPath
>
> =A0 =A0 strParty=3DRequest.Form(strParty)
> =A0 =A0 strNewFile=3D"LETTERS\Letter" & Replace(strParty," ","") & ".doc"
> =A0 =A0 strFolderPath=3D"LETTERS"
>
> =A0 =A0 Dim objFSO,objFolder,objFile
> =A0 =A0 Set objFSO=3DServer.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
> =A0 =A0 Set objFolder=3DobjFSO.GetFolder(Server.MapPath(strFolderPath))
>
> =A0 =A0 Const ForAppending=3D8
> =A0 =A0 Const ForWriting=3D2
>
> =A0 =A0 If Not(objFSO.FileExists(Server.MapPath(strNewFile))) Then
> =A0 =A0 =A0 =A0 Set objFile=3DobjFSO.CreateTextFile(Server.MapPath(strNewF=
ile))
> =A0 =A0 Else
> =A0 =A0 =A0 =A0 Set
> objFile=3DobjFSO.OpenTextFile(Server.MapPath(strNewFile),For Writing)
> =A0 =A0 End If
>
> <<<<<<<<
>
> The above can be reduced to:-
>
> Set objFile=3DobjFSO.OpenTextFile(Server.MapPath(strNewFile),For Writing, T=
rue)
>
> There is no need to test for FileExist.
>
>
>
> =A0 =A0 objFile.WriteLine("............")
> =A0 =A0 objFile.WriteLine("............")
> =A0 =A0 objFile.WriteLine("............")
>
> <<<<<<<<
>
> Where is objFile.Close ?
>
> I'm no expert in office file formats but it surprises me that you can writ=
e
> a word document using a text stream object.
>
>
>
> =A0 =A0 'e-mail code using CDO.MESSAGE to send
> =A0 =A0 'the DOC file as an attachment comes here
>
> =A0 =A0 'deleting the DOC document after 5 hours
> =A0 =A0 For Each objFile In objFolder.Files
> =A0 =A0 =A0 =A0 If(InStr(objFile.Name,".doc")>0) Then
> =A0 =A0 =A0 =A0 =A0 =A0 If(DateDiff("n",objFile.DateLastModified,Now())>30=
0) Then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 objFile.Delete
> =A0 =A0 =A0 =A0 =A0 =A0 End If
> =A0 =A0 =A0 =A0 End If
> =A0 =A0 Next
>
> =A0 =A0 Set objFile=3DNothing
> =A0 =A0 Set objFSO=3DNothing
> <<<<<<<<
>
> >> My advice is don't use Office objects in ASP
> >Then how does one send Office documents as attachments in ASP?
>
> You're not using office objects so don't worry about it.
>
> --
> Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
>
> - Show quoted text -

>> 'e-mail code using CDO.MESSAGE to send
>> 'the DOC file as an attachment comes here

You have hit the nail on the head, Anthony. objFile.Close was what was
missing which caused that error. Thanks a lot of your help.

>> I'm no expert in office file formats but it surprises me that >> you can =
write a word document using a text stream object.

Why does that surprise you, Anthony?

Thanks once again,

Regards,

Ron

Re: Attachment Using CDO.MESSAGE

am 23.12.2007 16:10:45 von Bob Lehmann

>> Why does that surprise you, Anthony?
Because Word documents are a proprietary, binary format, as opposed to plain
text.

Create a file in Notepad as something.doc. Now open it, and try to save it
in Word, to see what I mean.

Bob Lehmannn

"RN1" wrote in message
news:a21927f8-e090-4dde-b666-a8bfb39ec6af@e23g2000prf.google groups.com...
On Dec 23, 6:12 pm, "Anthony Jones" wrote:
> "RN1" wrote in message
>
> news:2164bba1-97c6-408b-a59e-c31132e18e7f@i29g2000prf.google groups.com...
> On Dec 22, 6:08 pm, "Anthony Jones" wrote:
>
>
>
>
>
> > "RN1" wrote in message
>
> >news:22c8c699-74bf-4525-8332-a7851d885a8f@d27g2000prf.googl egroups.com...
>
> > > On Dec 15, 5:34 pm, "Anthony Jones" wrote:
> > > > "RN1" wrote in message
>
> >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
> attachment
> > > > > 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
> another
> > > > > 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.
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:
>
> <%
> Dim strParty,strNewFile,strFolderPath
>
> strParty=Request.Form(strParty)
> strNewFile="LETTERS\Letter" & Replace(strParty," ","") & ".doc"
> strFolderPath="LETTERS"
>
> Dim objFSO,objFolder,objFile
> Set objFSO=Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
> Set objFolder=objFSO.GetFolder(Server.MapPath(strFolderPath))
>
> Const ForAppending=8
> Const ForWriting=2
>
> If Not(objFSO.FileExists(Server.MapPath(strNewFile))) Then
> Set objFile=objFSO.CreateTextFile(Server.MapPath(strNewFile))
> Else
> Set
> objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWr iting)
> End If
>
> <<<<<<<<
>
> The above can be reduced to:-
>
> Set objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWr iting,
True)
>
> There is no need to test for FileExist.
>
>
>
> objFile.WriteLine("............")
> objFile.WriteLine("............")
> objFile.WriteLine("............")
>
> <<<<<<<<
>
> Where is objFile.Close ?
>
> I'm no expert in office file formats but it surprises me that you can
write
> a word document using a text stream object.
>
>
>
> '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=Nothing
> Set objFSO=Nothing
> <<<<<<<<
>
> >> My advice is don't use Office objects in ASP
> >Then how does one send Office documents as attachments in ASP?
>
> You're not using office objects so don't worry about it.
>
> --
> Anthony Jones - MVP ASP/ASP.NET- Hide quoted text -
>
> - Show quoted text -

>> 'e-mail code using CDO.MESSAGE to send
>> 'the DOC file as an attachment comes here

You have hit the nail on the head, Anthony. objFile.Close was what was
missing which caused that error. Thanks a lot of your help.

>> I'm no expert in office file formats but it surprises me that >> you can
write a word document using a text stream object.

Why does that surprise you, Anthony?

Thanks once again,

Regards,

Ron