create a word document in C#

Am trying to create a word document in C#.

But while debugging am getting an exception  " The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))"
for the lines.,
aDoc.Activate();
aDoc.Close(ref doSaveChanges,ref missing,ref missing);
                       WordApp.Quit(ref missing, ref missing, ref missing);
please suggest,,
thanks in advance
object missing = System.Reflection.Missing.Value;
             object fileName ="normal.dot"; 
            object newTemplate = false;
            object docType = 0;
            object isVisible = true;
            // Create a new Document, by calling the Add function in the Documents collection
            Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);
            // need to see the created document, so make it visible
            WordApp.Visible = true;
            aDoc.Activate();
            // Global Constant enumerations are members of Word and can be assigned to properties
            // Set alignment to the center of the document
            WordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            // Toggle the title to a Bold Font
            WordApp.Selection.Font.Bold = (int)Microsoft.Office.Interop.Word.WdConstants.wdToggle;
            // Type the Text of the Title that was inputted by the user in the Custom Dialog
            string docname = "test1";
            WordApp.Selection.TypeText(docname);
            object saveasdoc = "c:\\";
            aDoc.SaveAs(ref saveasdoc, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            //workflowProperties.Item.CopyTo(workflowProperties.WebUrl + "/" + "Destination Doc Lib" + "/" + workflowProperties.Item.File.Name);
            object doSaveChanges = false;
          
            aDoc.Close(ref doSaveChanges,ref missing,ref missing);
                       WordApp.Quit(ref missing, ref missing, ref missing);

Open in new window

LVL 1
amiteshanandAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel JungesCommented:
try to use another template or create you own instead using the normal.dot.
0
amiteshanandAuthor Commented:
no.. Its still the same exception.
Please suggest some other way out
0
Daniel JungesCommented:
maybe that the you have to set the ASPNET user permissions. You source probally runs without this exception when runned on an application.

check it please
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Daniel JungesCommented:
Add read-write permission to the folder to IUSR_*, Network_Service, ASPNET. Then, add this line to the web.config.

<identity impersonate="true"/>
0
amiteshanandAuthor Commented:
Oh its the same problem again..
i dont think there is any permission issues . I have set right al those issues.
Please suggest
0
Daniel JungesCommented:

I have tested you source on an Desktop application. It works fine without errors.

The only change needed was in
object saveasdoc = "c:\\";   <=  Invalid File Name

i have googled and found more threads that says to set read/write ASPNET permisions

regards
Junges
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amiteshanandAuthor Commented:
@junges
Its fixed now!!! thanx a lot..
The problems were because of office licence.
 
0
tulasisivaCommented:
Hi all,

When I tried to run the above code, im getting the error, Interop does not exists in the Microsoft Office assembly. Pls suggest me .. I need to create a word doc from a string content.

Thanks in advance.....
0
amiteshanandAuthor Commented:
This answer made me realise that there is no problem with code and then think from other perspective which eventually turned to be office license problem
0
savinirCommented:
hello all,

I am having the same issue. amiteshanand mentioned that it is because of office licence. can you pls tell me what is that issue and how to resolve it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.