You must Sign In to post a response.
  • Category: .NET

    Create word file at Client Machine

    Hello All..


    In my project, I am creating .doc file using Microsoft.Office.Interop.Word and convert that doc file in pdf format. But when run the application at two different machine, it gives error. Because winword process open at server side and never delete it.

    Can any one knows how to create and open document file at client side?

    Thanks In advance.
  • #764549
    It is because of the access issue

    Following are some of the tips

    1. Create the document with the name contains current date time seconds.
    2. Once you done your process delete the document
    3. So that the access issue will not happen.

    By Nathan
    Direction is important than speed

  • #764551
    Please clarify some points
    1. is your application is windows based or web based ?
    2. What is your code, please post it so that we can help you better
    3. Have you Close document object ?
    4. Have you call Quit() method of word document object

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764554
    My application is web application. I close word document object and marshal it. But when two user access same time then its gives error. Because in process there are two "winword" process. So when it try to open word file it gives error. I giving code in short

    string fnametoc = Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".doc";
    object oOpenNametoc = (object)fnametoc;
    object missingtoc = System.Reflection.Missing.Value;
    Document wordDocument;
    Application wdApp = new Application();
    wdApp.Caption = DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss_fff").Replace(":", "_");
    wdApp.Visible = true;
    try
    {

    wordDocument = wdApp.Documents.Open(ref oOpenNametoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc, ref missingtoc);

    // wdApp.Visible = true;
    wordDocument.TablesOfContents[1].Update();

    wordDocument.Fields.Update();
    wordDocument.Save();
    wordDocument.Close(ref missingtoc, ref missingtoc, ref missingtoc);

    if (wdApp != null)
    {
    ((OW._Application)wdApp).Quit(ref missing, ref missing, ref missing);
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wdApp);
    wdApp = null;
    }

    if (Convert2PDF.ConvertDocument(Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".doc"))
    {

    deleteFile(Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".doc"); ---In that function, it delete doc file.
    string path = Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".pdf";

    ScriptManager.RegisterStartupScript(this, this.GetType(), "PDFPreview", "openPreviewPdf('" + outputfn + "');", true);


    }
    }
    catch (Exception ex)
    {
    deleteFile(Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".doc");
    lblerror.Text += Common_Functions.get_error_message("E0348");// "Error in Table of Content.....";
    }
    finally
    {
    // lblerror.Text += "Finnaly";
    deleteFile(Server.MapPath("~/PDF_Folder/Audit_Publish") + @"\" + outputfn + ".doc");
    //killWordProcess();
    if (wdApp != null)
    {
    ((OW._Application)wdApp).Quit(ref missing, ref missing, ref missing);
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(wdApp);
    wdApp = null;
    }
    }

  • #764556
    when you have deploy your application on server then it needs special rights to work with interop object. if you have less right to logged in user then this problem occur, winword object does not get destroyed.
    Do you open same file with different user ?

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764557
    No. when file is created its name is date,time, second. so every time filename is different. But still winword process not get Quit.

  • #764565
    check if following code line is execute successfully
    ((OW._Application)wdApp).Quit(ref missing, ref missing, ref missing);
    if yes, then try give following access permission
    1.In the command line put DCOMCNFG
    2.Component Services -> Computers -> My Computer -> DCOM Config
    3.Find "Microsoft Word 97 - 2003 Document" (If it is missing check if your Word is also 64 bit (if your Windows is))
    4.Right click -> Properties
    5.Go To Tab Security and Edit the "Customize" radio buttons so that IIS_IUSRS could have rights for launch and access
    6.Go to Tab Identity and choose "The interactive user"
    7.Apply changes and try again
    8.If all this fails, go also to tab "General" and in "Authentication Level" drop down choose "None".
    OR
    1.In the command line put DCOMCNFG
    2.Expand Console Root > Component Service > Computers, right-click on My Computer, And Select Properties
    3.In the Tab COM Security > Launch and Activation Permissions Click in Edit Default
    4.Add the User (Ex. IIS_IUSRS) or service
    5.Check Allow Local Launch and Local Activation
    May be you can switch to below link
    http://www.bloing.net/2011/01/how-to-make-iis7-play-nice-with-office-interop/

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764589
    Hi,

    While open file in server side at a time 2 users, my suggestion is file name should be combination of UserId, date&time. In that case you won't be face any issue.

    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments