Results 1 to 11 of 11

Thread: Creating word documents in asp.net *RESOLVED*

  1. #1

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Creating word documents in asp.net *RESOLVED*

    I'm trying to create and write a word document within asp.net using:
    Code:
    Word.ApplicationClass WordApp = new Word.ApplicationClass();
    Does anyone know of a reference for all the objects I can use in word?

    DJ
    Last edited by dj4uk; Jul 7th, 2004 at 05:11 AM.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Something like this:
    PHP Code:
    object objFileName Server.MapPath("MyDocs") + "\\MyDocument.doc";
    object missing System.Reflection.Missing.Value;

    Word.ApplicationClass objWord = new Word.ApplicationClass();
    Word.Document objDoc objWord.Documents.Add(ref missingref missingref missingref missing);
    objDoc.Activate();

    objWord.Selection.TypeText("This is my text");
    objWord.Selection.TypeParagraph();
    objDoc.SaveAs(ref objFileNameref missingref missingref missingref missingref missingref missingref missingref missingref missingref missing);
                
            
    objDoc.Close(ref missingref missingref missing);
    objWord.Application.Quit(ref missingref missingref missing); 

  3. #3

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Thanks for that Serge - I'll give it a go.

    Do I need any import or using statements?

    DJ

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You will need to add a reference to Microsoft Word library. Also you will have to change permissions for this library to be used through the web app by using dcomcnfg

  5. #5

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    You don't happen to know where this Word library is stored? I'm guessing it probably a dll file.

    DJ

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Actually, its an ActiveX EXE. In your solution explorer right click on the refereces folder and select Add Reference. Then select COM tab and check Microsoft Word 8.0 (or any other version you have installed).

  7. #7

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    I don't have Visual Studio .NET unfortunately (Billy Gates charges to much for humble me!) - could you let me know the path and name of the file.

    Thanks very much for all your help - it's much appreciated!

    DJ

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Usually it's in:

    C:\Program Files\Microsoft Office\Office\WinWord.EXE

  9. #9
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Actually, you can't reference an EXE.
    The file is an object library:

    C:\Program Files\Microsoft Office\Office\MSWord*.olb

    where * is 8 for Word97 or 9 for Word 2000

  10. #10

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    In the end I found a better way - downloading the primary interop assemblies (PIAs) from Microsoft.

    Thanks for all your help tho'.

    Anyone know of a good online resource for the word document model?

    Cheers

    DJ

  11. #11

    Thread Starter
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    I'll answer my own question - http://msdn.microsoft.com/library/de.../womthquit.asp.

    DJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width