none
Word Mail Merge with Asp .net RRS feed

  • Question

  • Dear all,

       My question is differ from others, about word mail merge. I have created word mail merge document by creating ODC in my (ASP .NET) web application. Now i planned to move my application into another server. Nearly 250 templates are created with their ODC within my application. Suggestion is given to me is that open 250 ODC with notepad and change server name. Yes, I tried for sample one. But every time,it asked select data source wizard when i ran mail merge. Is any other option exist to simply make changes to run 250 mail merge easily.It is very urgent. So friends,please idea me. 

    Friday, April 26, 2013 5:04 AM

Answers

  • Hi vadugan,

    I am reasonably sure that what you are going to have to do is replace all the instances of your old server name by the new server name in a number of possible places in your documents. The trouble is that although you might hope that the .odc acts as an "indirect" definition of your data source, in fact Word embeds the actual details of your data source in the document and does not update them automatically from the .odc.

    You might be able to do that if you have SharePoint server and the relevant Word Automation Services, but if so, you would have to ask elsewhere. In particular, if you have older .doc and .dot files, the suggestion I am about to make will not work.

    Since you are working server side I suspect the only way to fix this is probably to process all your .docx (and potentially .docm, .dotx and .dotm) documents to fix the various values in the XML. I don't have properly tested code to do that, but do have some very crude experimental code that may help you get started. It is written in VB.NET, using Visual Studio 2010, and uses the .NET FrameWork v. 4 and the Open XML SDK. If you don't have Visual Studio, the best you will be able to do with this code is to find someone who can turn it into a working project for you - I am certainly not ina position to do that.

    At the moment, the code present a simple Windows form, lets you specify an old server name, a new server name, select one .docx, and replaces the old name by the new name everywhere in the various places that matter. So it is very important that you can specify the old server name and the new server name in a way that will avoid unintended replacements.

    What I suggest is that you make back up copies of a few test files, then open the code in Visual Studio and try it out. If  it does not solve the problem for those files and you cannot see why, there is probably something wrong with my approach. If it does solve the problem, then you will need to modify the code so that it fixes all your files rather than just one at a time. Either way, I can try to help, but I am pretty sure that you will get far faster and more expert help from people in the relevant Open XML SDK group here, and that is what I suggest you do. But if you do make progress, please post back here.

    The code for the whole project is in a ZIP file on my skydrive at 

    http://goo.gl/BJ0rb

    That might not initiate a download - if not, look for the file called "2013042801 fixmailmergesource.zip"

    I have posted the main code below for anyone who wants to see what I believe needs to be changed in the .docx files.

    Imports System
    Imports System.Linq
    Imports DocumentFormat.OpenXml
    Imports DocumentFormat.OpenXml.Packaging
    Imports DocumentFormat.OpenXml.Wordprocessing
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Application.Exit()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
            Dim myDataSourceReference As DataSourceReference
            Dim myDoc As WordprocessingDocument
            Dim myHeaderSource As HeaderSource
            Dim myMailMerge As MailMerge
            Dim myNewRelationship As ExternalRelationship
            Dim myODSO As DataSourceObject
            Dim myODSOSourceReference As SourceReference
            Dim myOldRelationship As ExternalRelationship
            Dim mySettingsPart As DocumentSettingsPart
            Dim myUri As System.Uri
            Try
                If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    Me.Button2.Enabled = False
                    Me.RichTextBox1.AppendText("Processing file: " & OpenFileDialog1.FileName & vbCrLf)
                    myDoc = WordprocessingDocument.Open(OpenFileDialog1.FileName, True)
                    mySettingsPart = myDoc.MainDocumentPart.DocumentSettingsPart
                    myMailMerge = mySettingsPart.Settings.FirstOrDefault(Function(lName) lName.LocalName = "mailMerge")
                    If Not (myMailMerge Is Nothing) Then
                        ' For historical reasons (I think!) there may be two descriptions of the data source details,
                        ' one directly within the <w:MailMerge> element, and one within a <w:odso> child element.
                        ' The odso data + the query will probably be used if it is there, but we had better change
                        ' everything
    
                        ' First, the non-odso data.
                        ' Do any of your file names (all .odc files?) contain the server name? If so,
                        ' you will need to modify the file name, which is specified via a relationship
                        myDataSourceReference = myMailMerge.DataSourceReference
                        If Not (myDataSourceReference Is Nothing) Then
                            myOldRelationship = mySettingsPart.GetExternalRelationship(myDataSourceReference.Id)
                            If Not (myOldRelationship Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old data source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                            System.UriKind.Absolute)
                                myNewRelationship = _
                                    mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                    myUri, _
                                    myMailMerge.DataSourceReference.Id)
                                Me.RichTextBox1.AppendText("New data source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                            Else
                                ' if there is no relationship, we should probably do more than merely report an error
                                Me.RichTextBox1.AppendText("Expected data source relationship not found." & vbCrLf)
                            End If
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO data source." & vbCrLf)
                        End If
    
                        ' It is highly unlikely that you will have Header Source names (As far as I can remember, you can 
                        ' save a .docx with a Header Source but Word may not recognise the XML when you re-open)
                        ' but just in case ...
    
                        myHeaderSource = myMailMerge.HeaderSource
                        If Not (myHeaderSource Is Nothing) Then
                            myOldRelationship = mySettingsPart.GetExternalRelationship(myHeaderSource.Id)
                            If Not (myOldRelationship Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old header source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                            System.UriKind.Absolute)
                                myNewRelationship = _
                                    mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                    myUri, _
                                    myMailMerge.HeaderSource.Id)
                                Me.RichTextBox1.AppendText("New header source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                            Else
                                ' if there is no relationship, we should probably flag an error
                                Me.RichTextBox1.AppendText("Expected header source relationship not found." & vbCrLf)
                            End If
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO header source." & vbCrLf)
                        End If
    
                        ' The connection string
                        If Not (myMailMerge.ConnectString Is Nothing) Then
                            Me.RichTextBox1.AppendText("Old connection string: " & myMailMerge.ConnectString.Val.ToString & vbCrLf)
                            myMailMerge.ConnectString.Val = Replace(LCase(myMailMerge.ConnectString.Val), _
                                                                        LCase(tbOldServerName.Text), tbNewServerName.Text, 1)
                            Me.RichTextBox1.AppendText("New connection string: " & myMailMerge.ConnectString.Val.ToString & vbCrLf)
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO connection string." & vbCrLf)
                        End If
                        ' The query string
                        ' Only queries that reference "text type" files would be likely to have server names embedded in them
                        ' For example, if you only have SQL Server queries it may be better to ocmment out this chunk of code
                        If Not (myMailMerge.Query Is Nothing) Then
                            Me.RichTextBox1.AppendText("Old query string: " & myMailMerge.Query.Val.ToString & vbCrLf)
                            myMailMerge.Query.Val = Replace(LCase(myMailMerge.Query.Val), _
                                                    LCase(tbOldServerName.Text), _
                                                    tbNewServerName.Text)
                            Me.RichTextBox1.AppendText("New query string: " & myMailMerge.Query.Val.ToString & vbCrLf)
                        Else
                            Me.RichTextBox1.AppendText("No query string." & vbCrLf)
                        End If
    
                        ' Now the ODSO stuff
                        myODSO = myMailMerge.DataSourceObject
                        If Not (myODSO Is Nothing) Then
                            ' there should be another external file reference
                            myODSOSourceReference = myODSO.SourceReference
                            If Not (myODSOSourceReference Is Nothing) Then
                                myOldRelationship = mySettingsPart.GetExternalRelationship(myODSOSourceReference.Id)
                                If Not (myOldRelationship Is Nothing) Then
                                    Me.RichTextBox1.AppendText("Old ODSO data source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                    mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                    myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                    LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                                System.UriKind.Absolute)
                                    myNewRelationship = _
                                        mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                        myUri, _
                                        myODSOSourceReference.Id)
                                    Me.RichTextBox1.AppendText("New ODSO data source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                                Else
                                    ' if there is no relationship, we should probably do more than merely report an error
                                    Me.RichTextBox1.AppendText("Expected ODSO data source relationship not found." & vbCrLf)
                                End If
                            Else
                                Me.RichTextBox1.AppendText("No ODSO data source." & vbCrLf)
                            End If
    
                            ' there should be a UDL connection string
                            If Not (myODSO.UdlConnectionString Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old ODSO connection string: " & myODSO.UdlConnectionString.Val.ToString & vbCrLf)
                                myODSO.UdlConnectionString.Val = _
                                        Replace(LCase(myODSO.UdlConnectionString.Val), _
                                        LCase(tbOldServerName.Text), _
                                        tbNewServerName.Text)
                                Me.RichTextBox1.AppendText("New ODSO connection string: " & myODSO.UdlConnectionString.Val.ToString & vbCrLf)
                            Else
                                Me.RichTextBox1.AppendText("No ODSO connection string." & vbCrLf)
                            End If
    
                        End If
    
    
                    Else
                        Me.RichTextBox1.AppendText("No Mailmerge settings found." & vbCrLf)
                    End If
    
                        mySettingsPart.Settings.Save()
                    End If
    
            Catch ex As Exception
    
            Finally
                If Not myDoc Is Nothing Then
                    myDoc.Close()
                End If
                Me.Button2.Enabled = True
            End Try
        End Sub
    
      
        Private Sub tbNewServerName_TextChanged(sender As Object, e As System.EventArgs) Handles tbNewServerName.TextChanged
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    
        Private Sub tbOldServerName_TextChanged(sender As Object, e As System.EventArgs) Handles tbOldServerName.TextChanged
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    End Class




    Peter Jamieson


    Sunday, April 28, 2013 7:51 PM
  • Hi Peter

    Yes, I thought of you the minute I saw this question :-) Glad it's something you've been able to sink your teeth into, and that you, too, think "hacking" the open xml file format is the way to go with this. I am surprised to learn that the information is stored in multiple locations within the document!

    The other suggestion I considered making to vadugan was, that he migrate the entire solution to use Open XML, rather than mail merge as this would be much more appropriate for server-side. But I suspect that would require more time than is immediately available. But certainly something that should be looked at for the future...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 29, 2013 6:24 AM
    Moderator

All replies

  • Hi vadugan

    I know only one person who has ever tried to investigate the use of *.odc files in detail, and he came out of it feeling extremely frustrated. I was hoping he'd see this and jump in, but apparently not (yet)...

    Which version of Word / file format is involved in your case?

    Some more recent versions of Word cache mail merge information and that could be the issue in this case. If these are *.docx files it would be a good idea to open one up as a Zip-Package (add .zip to the file extension) and see what kind of information has been stored in there. Also, if this is the *.docx file format and it does turn out that the document is storing information that should be changed, you can manipulate all the documents at the Package level, rather than needing to open them in Word.

    An important resource for you (assuming *.docx file format) will be "Ecma Office Open XML Part 1 - Fundamentals And Markup Language Reference.pdf" which is part of a free download you can get from the Ecma site. Most of the information is also available on MSDN. For your issue, the section 17.14 Mail Merge is relevant and describes what information is stored where, in what format.

    17.14 Mail Merge

     

    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, April 28, 2013 5:48 AM
    Moderator
  • Hi vadugan,

    I am reasonably sure that what you are going to have to do is replace all the instances of your old server name by the new server name in a number of possible places in your documents. The trouble is that although you might hope that the .odc acts as an "indirect" definition of your data source, in fact Word embeds the actual details of your data source in the document and does not update them automatically from the .odc.

    You might be able to do that if you have SharePoint server and the relevant Word Automation Services, but if so, you would have to ask elsewhere. In particular, if you have older .doc and .dot files, the suggestion I am about to make will not work.

    Since you are working server side I suspect the only way to fix this is probably to process all your .docx (and potentially .docm, .dotx and .dotm) documents to fix the various values in the XML. I don't have properly tested code to do that, but do have some very crude experimental code that may help you get started. It is written in VB.NET, using Visual Studio 2010, and uses the .NET FrameWork v. 4 and the Open XML SDK. If you don't have Visual Studio, the best you will be able to do with this code is to find someone who can turn it into a working project for you - I am certainly not ina position to do that.

    At the moment, the code present a simple Windows form, lets you specify an old server name, a new server name, select one .docx, and replaces the old name by the new name everywhere in the various places that matter. So it is very important that you can specify the old server name and the new server name in a way that will avoid unintended replacements.

    What I suggest is that you make back up copies of a few test files, then open the code in Visual Studio and try it out. If  it does not solve the problem for those files and you cannot see why, there is probably something wrong with my approach. If it does solve the problem, then you will need to modify the code so that it fixes all your files rather than just one at a time. Either way, I can try to help, but I am pretty sure that you will get far faster and more expert help from people in the relevant Open XML SDK group here, and that is what I suggest you do. But if you do make progress, please post back here.

    The code for the whole project is in a ZIP file on my skydrive at 

    http://goo.gl/BJ0rb

    That might not initiate a download - if not, look for the file called "2013042801 fixmailmergesource.zip"

    I have posted the main code below for anyone who wants to see what I believe needs to be changed in the .docx files.

    Imports System
    Imports System.Linq
    Imports DocumentFormat.OpenXml
    Imports DocumentFormat.OpenXml.Packaging
    Imports DocumentFormat.OpenXml.Wordprocessing
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            Application.Exit()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
            Dim myDataSourceReference As DataSourceReference
            Dim myDoc As WordprocessingDocument
            Dim myHeaderSource As HeaderSource
            Dim myMailMerge As MailMerge
            Dim myNewRelationship As ExternalRelationship
            Dim myODSO As DataSourceObject
            Dim myODSOSourceReference As SourceReference
            Dim myOldRelationship As ExternalRelationship
            Dim mySettingsPart As DocumentSettingsPart
            Dim myUri As System.Uri
            Try
                If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    Me.Button2.Enabled = False
                    Me.RichTextBox1.AppendText("Processing file: " & OpenFileDialog1.FileName & vbCrLf)
                    myDoc = WordprocessingDocument.Open(OpenFileDialog1.FileName, True)
                    mySettingsPart = myDoc.MainDocumentPart.DocumentSettingsPart
                    myMailMerge = mySettingsPart.Settings.FirstOrDefault(Function(lName) lName.LocalName = "mailMerge")
                    If Not (myMailMerge Is Nothing) Then
                        ' For historical reasons (I think!) there may be two descriptions of the data source details,
                        ' one directly within the <w:MailMerge> element, and one within a <w:odso> child element.
                        ' The odso data + the query will probably be used if it is there, but we had better change
                        ' everything
    
                        ' First, the non-odso data.
                        ' Do any of your file names (all .odc files?) contain the server name? If so,
                        ' you will need to modify the file name, which is specified via a relationship
                        myDataSourceReference = myMailMerge.DataSourceReference
                        If Not (myDataSourceReference Is Nothing) Then
                            myOldRelationship = mySettingsPart.GetExternalRelationship(myDataSourceReference.Id)
                            If Not (myOldRelationship Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old data source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                            System.UriKind.Absolute)
                                myNewRelationship = _
                                    mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                    myUri, _
                                    myMailMerge.DataSourceReference.Id)
                                Me.RichTextBox1.AppendText("New data source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                            Else
                                ' if there is no relationship, we should probably do more than merely report an error
                                Me.RichTextBox1.AppendText("Expected data source relationship not found." & vbCrLf)
                            End If
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO data source." & vbCrLf)
                        End If
    
                        ' It is highly unlikely that you will have Header Source names (As far as I can remember, you can 
                        ' save a .docx with a Header Source but Word may not recognise the XML when you re-open)
                        ' but just in case ...
    
                        myHeaderSource = myMailMerge.HeaderSource
                        If Not (myHeaderSource Is Nothing) Then
                            myOldRelationship = mySettingsPart.GetExternalRelationship(myHeaderSource.Id)
                            If Not (myOldRelationship Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old header source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                            System.UriKind.Absolute)
                                myNewRelationship = _
                                    mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                    myUri, _
                                    myMailMerge.HeaderSource.Id)
                                Me.RichTextBox1.AppendText("New header source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                            Else
                                ' if there is no relationship, we should probably flag an error
                                Me.RichTextBox1.AppendText("Expected header source relationship not found." & vbCrLf)
                            End If
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO header source." & vbCrLf)
                        End If
    
                        ' The connection string
                        If Not (myMailMerge.ConnectString Is Nothing) Then
                            Me.RichTextBox1.AppendText("Old connection string: " & myMailMerge.ConnectString.Val.ToString & vbCrLf)
                            myMailMerge.ConnectString.Val = Replace(LCase(myMailMerge.ConnectString.Val), _
                                                                        LCase(tbOldServerName.Text), tbNewServerName.Text, 1)
                            Me.RichTextBox1.AppendText("New connection string: " & myMailMerge.ConnectString.Val.ToString & vbCrLf)
                        Else
                            Me.RichTextBox1.AppendText("No non-ODSO connection string." & vbCrLf)
                        End If
                        ' The query string
                        ' Only queries that reference "text type" files would be likely to have server names embedded in them
                        ' For example, if you only have SQL Server queries it may be better to ocmment out this chunk of code
                        If Not (myMailMerge.Query Is Nothing) Then
                            Me.RichTextBox1.AppendText("Old query string: " & myMailMerge.Query.Val.ToString & vbCrLf)
                            myMailMerge.Query.Val = Replace(LCase(myMailMerge.Query.Val), _
                                                    LCase(tbOldServerName.Text), _
                                                    tbNewServerName.Text)
                            Me.RichTextBox1.AppendText("New query string: " & myMailMerge.Query.Val.ToString & vbCrLf)
                        Else
                            Me.RichTextBox1.AppendText("No query string." & vbCrLf)
                        End If
    
                        ' Now the ODSO stuff
                        myODSO = myMailMerge.DataSourceObject
                        If Not (myODSO Is Nothing) Then
                            ' there should be another external file reference
                            myODSOSourceReference = myODSO.SourceReference
                            If Not (myODSOSourceReference Is Nothing) Then
                                myOldRelationship = mySettingsPart.GetExternalRelationship(myODSOSourceReference.Id)
                                If Not (myOldRelationship Is Nothing) Then
                                    Me.RichTextBox1.AppendText("Old ODSO data source file name: " & myOldRelationship.Uri.ToString & vbCrLf)
                                    mySettingsPart.DeleteExternalRelationship(myOldRelationship)
                                    myUri = New System.Uri(Replace(LCase(myOldRelationship.Uri.AbsoluteUri), _
                                                                    LCase(tbOldServerName.Text), tbNewServerName.Text, 1), _
                                                                System.UriKind.Absolute)
                                    myNewRelationship = _
                                        mySettingsPart.AddExternalRelationship(myOldRelationship.RelationshipType, _
                                        myUri, _
                                        myODSOSourceReference.Id)
                                    Me.RichTextBox1.AppendText("New ODSO data source file name: " & myNewRelationship.Uri.ToString & vbCrLf)
                                Else
                                    ' if there is no relationship, we should probably do more than merely report an error
                                    Me.RichTextBox1.AppendText("Expected ODSO data source relationship not found." & vbCrLf)
                                End If
                            Else
                                Me.RichTextBox1.AppendText("No ODSO data source." & vbCrLf)
                            End If
    
                            ' there should be a UDL connection string
                            If Not (myODSO.UdlConnectionString Is Nothing) Then
                                Me.RichTextBox1.AppendText("Old ODSO connection string: " & myODSO.UdlConnectionString.Val.ToString & vbCrLf)
                                myODSO.UdlConnectionString.Val = _
                                        Replace(LCase(myODSO.UdlConnectionString.Val), _
                                        LCase(tbOldServerName.Text), _
                                        tbNewServerName.Text)
                                Me.RichTextBox1.AppendText("New ODSO connection string: " & myODSO.UdlConnectionString.Val.ToString & vbCrLf)
                            Else
                                Me.RichTextBox1.AppendText("No ODSO connection string." & vbCrLf)
                            End If
    
                        End If
    
    
                    Else
                        Me.RichTextBox1.AppendText("No Mailmerge settings found." & vbCrLf)
                    End If
    
                        mySettingsPart.Settings.Save()
                    End If
    
            Catch ex As Exception
    
            Finally
                If Not myDoc Is Nothing Then
                    myDoc.Close()
                End If
                Me.Button2.Enabled = True
            End Try
        End Sub
    
      
        Private Sub tbNewServerName_TextChanged(sender As Object, e As System.EventArgs) Handles tbNewServerName.TextChanged
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    
        Private Sub tbOldServerName_TextChanged(sender As Object, e As System.EventArgs) Handles tbOldServerName.TextChanged
            If tbOldServerName.Text.Trim = "" Or tbNewServerName.Text.Trim = "" Then
                Button1.Enabled = False
            Else
                If tbOldServerName.Text.Trim = tbNewServerName.Text.Trim Then
                    Button1.Enabled = False
                Else
                    Button1.Enabled = True
                End If
            End If
        End Sub
    End Class




    Peter Jamieson


    Sunday, April 28, 2013 7:51 PM
  • Hi Cindy,

    As you will see from my other post, I spent some time over the past few days trying to get a grip on what actually needs to be done. Now is as good a time as any to stop, as it's pointless continuing unless it actually fixes the problem for at least some files for the OP.

    AFAIK changing the .odc does not help in itself because it isn't a "true indirection file". Although the .odcs do need to be changed. But everything is actually embedded in the .docx and does not change until you reconnect (I think).

    I should perhaps have directed the OP to the Open XML SDK group earlier, but it has been useful to re-examine what elements etc. actually need to be modified in the source.


    Peter Jamieson

    Sunday, April 28, 2013 7:58 PM
  • Hi Peter

    Yes, I thought of you the minute I saw this question :-) Glad it's something you've been able to sink your teeth into, and that you, too, think "hacking" the open xml file format is the way to go with this. I am surprised to learn that the information is stored in multiple locations within the document!

    The other suggestion I considered making to vadugan was, that he migrate the entire solution to use Open XML, rather than mail merge as this would be much more appropriate for server-side. But I suspect that would require more time than is immediately available. But certainly something that should be looked at for the future...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 29, 2013 6:24 AM
    Moderator
  • that he migrate the entire solution to use Open XML

    Good point.

    re. the multiple locations, there is an explanation of sorts in the ISO standard. The two most relevant chunks are in the MSDN documentation here:

    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.sourcereference.aspx

    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.datasourcereference.aspx


    Peter Jamieson

    Monday, April 29, 2013 9:34 AM