Attachment Using CDO.MESSAGE

Discussion in 'ASP General' started by RN1, Dec 14, 2007.

  1. RN1

    RN1 Guest

    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?
    RN1, Dec 14, 2007
    #1
    1. Advertising

  2. "RN1" <> wrote in message
    news:...
    > 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 Jones, Dec 15, 2007
    #2
    1. Advertising

  3. RN1

    RN1 Guest

    On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > "RN1" <> wrote in message
    >
    > news:...
    >
    > > 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.

    Anyway, how do I ensure that the Word object is not holding the file
    open?

    I remember doing the same thing but using CDONTS.MAIL (instead of
    CDO.MESSAGE) to send the mail & the mail was delivered successfully
    along with the attachment. The problem creeps up when I use
    CDO.MESSAGE.
    RN1, Dec 17, 2007
    #3
  4. RN1

    RN1 Guest

    On Dec 17, 8:08 pm, RN1 <> wrote:
    > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    >
    >
    >
    >
    >
    > > "RN1" <> wrote in message

    >
    > >news:...

    >
    > > > 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.  Asthe
    > > 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.
    >
    > Anyway, how do I ensure that the Word object is not holding the file
    > open?
    >
    > I remember doing the same thing but using CDONTS.MAIL (instead of
    > CDO.MESSAGE) to send the mail & the mail was delivered successfully
    > along with the attachment. The problem creeps up when I use
    > CDO.MESSAGE.- Hide quoted text -
    >
    > - Show quoted text -


    Anyone?

    Ron
    RN1, Dec 21, 2007
    #4
  5. "RN1" <> wrote in message
    news:...
    > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > "RN1" <> wrote in message
    > >
    > > news:...
    > >
    > > > 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
    Anthony Jones, Dec 22, 2007
    #5
  6. RN1

    RN1 Guest

    On Dec 22, 6:08 pm, "Anthony Jones" <> wrote:
    > "RN1" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > > "RN1" <> wrote in message

    >
    > > >news:....

    >
    > > > > 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),ForWriting)
    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=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?

    Thanks,

    Ron
    RN1, Dec 23, 2007
    #6
  7. "RN1" <> wrote in message
    news:...
    On Dec 22, 6:08 pm, "Anthony Jones" <> wrote:
    > "RN1" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > > "RN1" <> wrote in message

    >
    > >

    >news:...
    >
    > > > > 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),ForWriting)
    End If

    <<<<<<<<

    The above can be reduced to:-

    Set objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWriting, 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
    Anthony Jones, Dec 23, 2007
    #7
  8. RN1

    RN1 Guest

    On Dec 23, 6:12 pm, "Anthony Jones" <> wrote:
    > "RN1" <> wrote in message
    >
    > news:...
    > On Dec 22, 6:08 pm, "Anthony Jones" <> wrote:
    >
    >
    >
    >
    >
    > > "RN1" <> wrote in message

    >
    > >news:...

    >
    > > > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > > > "RN1" <> wrote in message

    >
    > >news:...

    >
    > > > > > 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),ForWriting)
    >     End If
    >
    > <<<<<<<<
    >
    > The above can be reduced to:-
    >
    > Set objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWriting, 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
    RN1, Dec 23, 2007
    #8
  9. RN1

    Bob Lehmann Guest

    >> 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:...
    On Dec 23, 6:12 pm, "Anthony Jones" <> wrote:
    > "RN1" <> wrote in message
    >
    > news:...
    > On Dec 22, 6:08 pm, "Anthony Jones" <> wrote:
    >
    >
    >
    >
    >
    > > "RN1" <> wrote in message

    >
    > >news:...

    >
    > > > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > > > "RN1" <> wrote in message

    >
    > >news:...

    >
    > > > > > 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),ForWriting)
    > End If
    >
    > <<<<<<<<
    >
    > The above can be reduced to:-
    >
    > Set objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWriting,

    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
    Bob Lehmann, Dec 23, 2007
    #9
  10. RN1

    RN1 Guest

    On Dec 23, 8:10 pm, "Bob Lehmann" <> wrote:
    > >> 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:...
    > On Dec 23, 6:12 pm, "Anthony Jones" <> wrote:
    >
    >
    >
    >
    >
    > > "RN1" <> wrote in message

    >
    > >news:...
    > > On Dec 22, 6:08 pm, "Anthony Jones" <> wrote:

    >
    > > > "RN1" <> wrote in message

    >
    > > >news:....

    >
    > > > > On Dec 15, 5:34 pm, "Anthony Jones" <> wrote:
    > > > > > "RN1" <> wrote in message

    >
    > > >news:....

    >
    > > > > > > 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),ForWriting)
    > > End If

    >
    > > <<<<<<<<

    >
    > > The above can be reduced to:-

    >
    > > Set objFile=objFSO.OpenTextFile(Server.MapPath(strNewFile),ForWriting,

    > 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- Hide quoted text -
    >
    > - Show quoted text -


    >> 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


    OK....now I understand why Anthony found that surprising but Bob when
    I created a "doc" document in the way you have suggested (i.e. first
    creating a "doc" file in NotePad & then saving it in Word) & then
    opened it in Word, Word generated the following message:

    ============================================
    Microsoft Word needs a converter to display the file correctly.
    ============================================

    Word also generated another message when I tried to save it but when I
    opened & saved the doc file which I created using the text stream
    object, Word didn't generate any message. So does that mean that the
    doc file created with the text stream object was created in the
    correct binary format?

    Thanks,

    Ron
    RN1, Dec 23, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rabbits77
    Replies:
    0
    Views:
    854
    rabbits77
    Feb 26, 2004
  2. NetNoise
    Replies:
    6
    Views:
    357
    NetNoise
    Jan 10, 2005
  3. CDO.MESSAGE ATTACHMENT

    , May 19, 2007, in forum: ASP General
    Replies:
    4
    Views:
    578
    Dave Anderson
    May 21, 2007
  4. SSG
    Replies:
    0
    Views:
    146
  5. Yosi

    CDO Message attachment rename

    Yosi, Jul 31, 2008, in forum: ASP General
    Replies:
    2
    Views:
    152
Loading...

Share This Page