locked
Microsoft Word Mail Merge Problem RRS feed

  • Question

  • User869274642 posted

    I wrote code to create label from Microsoft Word Mail Merge using Visual Studio 2008 ASP.NET C#. This is my code:

    public void CreateLabel(string strCSVPath, string strTemplatePath)
    {
                Object fileName = strTemplatePath;
    
                Object missing = System.Reflection.Missing.Value;
                Object oEmpty = "";
                Object oFalse = false;
                Object oTrue = true;
                Object oAutoFormat = word.WdOpenFormat.wdOpenFormatAuto;
    
                word.Application wApp = new word.Application();
                word.Document wDoc = wApp.Documents.Open(ref fileName,
                    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);
                word.MailMerge wMM = wDoc.MailMerge;
    
                wMM.OpenDataSource(strCSVPath, ref oAutoFormat, ref oTrue, ref oFalse, ref oTrue,
                                    ref oFalse, ref oEmpty, ref oEmpty, ref oFalse, ref oEmpty, ref oEmpty,
                                    ref oEmpty, ref oEmpty, ref oEmpty, ref missing, ref missing);
    
                wMM.DataSource.QueryString = "SELECT * FROM " + strCSVPath;
    
                wMM.Destination = word.WdMailMergeDestination.wdSendToNewDocument;
    
                wMM.Execute(ref oTrue);
    
                wDoc.Close(ref oFalse, ref missing, ref missing);
    
                wApp.Visible = true;
                wApp.ShowMe();
    
                // Release References.
                wMM = null;
                wDoc = null;
                wApp = null;
    }

    The expected result of code above is to show the word document that already embedded with the data. The result is work perfect when i run the code from "Debug Mode" / ASP.NET Development Server (when we press F5 key in Visual Studio). But it won't happened / works perfect when i accessed the page directly to the URL that provide by IIS. Is there anyone know what's wrong? Thank you Smile

    Tuesday, June 15, 2010 6:28 AM

All replies

  • User670707031 posted

    Will you know how to insert more than one mail merge fields in a single table cell?

    Monday, September 20, 2010 2:35 AM