Classic ASP question. Urgent !!!

Discussion in 'ASP General' started by Victor, Sep 25, 2006.

  1. Victor

    Victor Guest

    Hi, guys. We have a very old application that is written in classic ASP.
    It's sitting on a very old server. I am supposed to do a migration of this
    app to a new server. I copied all the files to a new server with Windows
    2000 Server on it (actually it's a virtual server) and installed SQL Server
    2000. The application works good, except for one little annoying thing. They
    use an Office Automation in this application. The word document is created
    based on some template and the values from SQL Server are inserted into this
    document. So, on the old server when you click on the report, it
    automatically generates a MS Word 2000 document and Opens it, so the user
    can view it and saves it to a temp directory. On this new server we have MS
    Word 2003 installed. So, when I click on the report, the Word document is
    created in a Temp directory, BUT... the document itself does not open
    automatically for a user to view. Can anyone help me with this issue, please
    ? I don't know much about classic ASP or Office automation. I am a SQL
    Server DBA, with some knowledge of .NET programming. But, I guess, at work
    you have to do what you have to do. Please, help !!!

    Thanks,

    Victor.
    Victor, Sep 25, 2006
    #1
    1. Advertising

  2. Victor

    McKirahan Guest

    "Victor" <> wrote in message
    news:...
    > Hi, guys. We have a very old application that is written in classic ASP.
    > It's sitting on a very old server. I am supposed to do a migration of this
    > app to a new server. I copied all the files to a new server with Windows
    > 2000 Server on it (actually it's a virtual server) and installed SQL

    Server
    > 2000. The application works good, except for one little annoying thing.

    They
    > use an Office Automation in this application. The word document is created
    > based on some template and the values from SQL Server are inserted into

    this
    > document. So, on the old server when you click on the report, it
    > automatically generates a MS Word 2000 document and Opens it, so the user
    > can view it and saves it to a temp directory. On this new server we have

    MS
    > Word 2003 installed. So, when I click on the report, the Word document is
    > created in a Temp directory, BUT... the document itself does not open
    > automatically for a user to view. Can anyone help me with this issue,

    please
    > ? I don't know much about classic ASP or Office automation. I am a SQL
    > Server DBA, with some knowledge of .NET programming. But, I guess, at work
    > you have to do what you have to do. Please, help !!!
    >
    > Thanks,
    >
    > Victor.


    Could you post the relevant code?

    Basicsally the subset of code referencing "Word.Application"; like:

    Const wdWindowStateMaximize = 1
    Set objMSW = CreateObject("Word.Application")
    objMSW.WindowState = wdWindowStateMaximize
    Set objDOC = objMSW.Documents.Open("C:\Temp\my.doc")
    McKirahan, Sep 25, 2006
    #2
    1. Advertising

  3. Victor

    VictorV Guest

    Here is the code:

    openrs rs, sSql


    if rs.Recordcount <> 0 then

    dim strScriptName
    dim strFileName

    strScriptName = Request.ServerVariables("SCRIPT_NAME")
    strScriptPath = server.MapPath(strScriptName)
    strFileName = left(strScriptPath, instrrev(strScriptPath, "\")) &
    GetParam("hdnReport")
    Dim app
    Set app = server.CreateObject("Word.Application")

    Dim doc
    Set doc = server.CreateObject("Word.Document")
    Set doc = app.Documents.Open(strFileName, , true)
    for each fld in rs.fields
    With doc.Content.Find
    .ClearFormatting
    .Text = "<<" & fld.name & ">>"
    .Replacement.ClearFormatting
    if isnull(fld.value) then
    .Replacement.Text = ""
    else
    if len(fld.value) > 80 then
    .Replacement.Text = left(cstr(fld.value), 80)
    else
    .Replacement.Text = cstr(fld.value)
    end if
    end if
    .Forward = True
    .Wrap = 1
    .Execute , , , , , , , , , , 2
    End With
    next

    dim strTempFileName
    strTempFileName = replace(replace(replace(replace(now(), "/", ""), "\",
    ""), " ", ""), ":", "") & ".doc"
    strFileName = left(strScriptPath, instrrev(strScriptPath, "\")) &
    "TempDocs\" & strTempFileName
    doc.SaveAs strFileName
    strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
    "TempDocs/" & strTempFileName

    doc.Close
    Set doc = Nothing
    app.Quit
    Set app = Nothing

    "McKirahan" wrote:

    > "Victor" <> wrote in message
    > news:...
    > > Hi, guys. We have a very old application that is written in classic ASP.
    > > It's sitting on a very old server. I am supposed to do a migration of this
    > > app to a new server. I copied all the files to a new server with Windows
    > > 2000 Server on it (actually it's a virtual server) and installed SQL

    > Server
    > > 2000. The application works good, except for one little annoying thing.

    > They
    > > use an Office Automation in this application. The word document is created
    > > based on some template and the values from SQL Server are inserted into

    > this
    > > document. So, on the old server when you click on the report, it
    > > automatically generates a MS Word 2000 document and Opens it, so the user
    > > can view it and saves it to a temp directory. On this new server we have

    > MS
    > > Word 2003 installed. So, when I click on the report, the Word document is
    > > created in a Temp directory, BUT... the document itself does not open
    > > automatically for a user to view. Can anyone help me with this issue,

    > please
    > > ? I don't know much about classic ASP or Office automation. I am a SQL
    > > Server DBA, with some knowledge of .NET programming. But, I guess, at work
    > > you have to do what you have to do. Please, help !!!
    > >
    > > Thanks,
    > >
    > > Victor.

    >
    > Could you post the relevant code?
    >
    > Basicsally the subset of code referencing "Word.Application"; like:
    >
    > Const wdWindowStateMaximize = 1
    > Set objMSW = CreateObject("Word.Application")
    > objMSW.WindowState = wdWindowStateMaximize
    > Set objDOC = objMSW.Documents.Open("C:\Temp\my.doc")
    >
    >
    >
    VictorV, Sep 25, 2006
    #3
  4. Victor

    McKirahan Guest

    "VictorV" <> wrote in message
    news:...

    [snip]

    > Here is the code:


    [snip]

    > Set app = server.CreateObject("Word.Application")
    > Set doc = server.CreateObject("Word.Document")


    You don't need the above line -- it's setting "doc" twice.

    > Set doc = app.Documents.Open(strFileName, , true)


    > > "Victor" <> wrote in message
    > > news:...
    > > > So, when I click on the report, the Word document is
    > > > created in a Temp directory, BUT... the document itself does not open
    > > > automatically for a user to view. Can anyone help me with this issue,

    > > please


    Did you see this code from my last post?
    What happens if you add it?

    > > Const wdWindowStateMaximize = 1
    > > Set app = CreateObject("Word.Application")
    > > app.WindowState = wdWindowStateMaximize


    Oh, this code will close the document so they couldn't see it anyway.

    > doc.Close
    > Set doc = Nothing
    > app.Quit
    > Set app = Nothing
    McKirahan, Sep 25, 2006
    #4
  5. Victor

    VictorV Guest

    Thanks for your help. It work now, but the problem wasn't code. Because code
    worked on that old machine. All I had to do was to add this new intranet site
    (the one on a new machine) to Trusted Sites in our group policy.

    Thanks again,
    Victor.

    "McKirahan" wrote:

    > "VictorV" <> wrote in message
    > news:...
    >
    > [snip]
    >
    > > Here is the code:

    >
    > [snip]
    >
    > > Set app = server.CreateObject("Word.Application")
    > > Set doc = server.CreateObject("Word.Document")

    >
    > You don't need the above line -- it's setting "doc" twice.
    >
    > > Set doc = app.Documents.Open(strFileName, , true)

    >
    > > > "Victor" <> wrote in message
    > > > news:...
    > > > > So, when I click on the report, the Word document is
    > > > > created in a Temp directory, BUT... the document itself does not open
    > > > > automatically for a user to view. Can anyone help me with this issue,
    > > > please

    >
    > Did you see this code from my last post?
    > What happens if you add it?
    >
    > > > Const wdWindowStateMaximize = 1
    > > > Set app = CreateObject("Word.Application")
    > > > app.WindowState = wdWindowStateMaximize

    >
    > Oh, this code will close the document so they couldn't see it anyway.
    >
    > > doc.Close
    > > Set doc = Nothing
    > > app.Quit
    > > Set app = Nothing

    >
    >
    >
    VictorV, Sep 25, 2006
    #5
  6. Victor

    McKirahan Guest

    "VictorV" <> wrote in message
    news:...
    > Thanks for your help. It work now, but the problem wasn't code. Because

    code
    > worked on that old machine. All I had to do was to add this new intranet

    site
    > (the one on a new machine) to Trusted Sites in our group policy.


    [SNIP]

    I'm glad you got it working.

    I found another line of code that seems unnecessary:

    strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
    "TempDocs/" & strTempFileName

    This is the line after
    doc.SaveAs strFileName
    which has "strFileName" assigned just before it.
    McKirahan, Sep 25, 2006
    #6
  7. Victor

    VictorV Guest

    I agree. This application is very old, and a lot of code is junky. The vendor
    that did this app doesn't exist anymore. I just inherited it and as long as
    it still works, I am not touching it. Otherwise, I would have to rewrite it
    completely.

    Victor.

    "McKirahan" wrote:

    > "VictorV" <> wrote in message
    > news:...
    > > Thanks for your help. It work now, but the problem wasn't code. Because

    > code
    > > worked on that old machine. All I had to do was to add this new intranet

    > site
    > > (the one on a new machine) to Trusted Sites in our group policy.

    >
    > [SNIP]
    >
    > I'm glad you got it working.
    >
    > I found another line of code that seems unnecessary:
    >
    > strFileName = left(strScriptName, instrrev(strScriptName, "/")) &
    > "TempDocs/" & strTempFileName
    >
    > This is the line after
    > doc.SaveAs strFileName
    > which has "strFileName" assigned just before it.
    >
    >
    >
    VictorV, Sep 26, 2006
    #7
    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. Bob [BVP]
    Replies:
    5
    Views:
    763
    Bob [BVP]
    Aug 9, 2004
  2. Gary Morris

    Classic ASP to ASP.Net migration question

    Gary Morris, Oct 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    455
    Gary Morris
    Oct 17, 2004
  3. Mark

    Classic ASP question

    Mark, Jun 25, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    822
    John Timney \(ASP.NET MVP\)
    Jun 26, 2005
  4. talkingwall
    Replies:
    6
    Views:
    1,387
    clintonG
    Jul 12, 2005
  5. David A. Beck
    Replies:
    10
    Views:
    1,005
    Scott McNair
    Apr 13, 2004
Loading...

Share This Page