Click here to Skip to main content
14,970,330 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I need to compare two word documents,
if both files are same its saying same,
if both files are different which word, which line also telling.

compare result in another file..

using asp.net,vb.net
Posted
Updated 6-Nov-11 23:45pm
v2
Comments
OriginalGriff 7-Nov-11 5:00am
   
And what have you tried so far?

use this namespace
Imports Word = Microsoft.Office.Interop.Word
Imports System.IO


code to compare

VB
Private Sub CompareDocument()
	Dim missing As Object = System.Reflection.Missing.Value

	'create a readonly variable of object type and assign it to false.

	Dim readonlyobj As Object = False

	Dim filename As Object = txtfile1.Text

	'create a word application object for processing the word file.

	Dim app As Word.Application = New Word.ApplicationClass()

	'create a word document object and open the above file..


	Dim doc As Word.Document = app.Documents.Open(filename, missing, readonlyobj, missing, missing, missing, _
		missing, missing, missing, missing, missing, missing, _
		missing, missing, missing, missing)

	Dim filenm As String = txtfile2.Text

	Dim nm As String = txtpath.Text + "\" & getfilename(txtfile1.Text)

	Dim filesavename As Object = nm


	doc.SaveAs(filesavename, missing, missing, missing, missing, missing, _
		missing, missing, missing, missing, missing, missing, _
		missing, missing, missing, missing)

	doc.TrackRevisions = True

	doc.ShowRevisions = True

	doc.PrintRevisions = True

	doc.Compare(filenm, missing, missing, missing, missing, missing, _
		missing, missing)

	doc.Close(missing, missing, missing)

	app.Quit(missing, missing, missing)

End Sub

Private Function getfilename(sfilename As String) As String
	Dim fin As New FileInfo(sfilename)
	Return fin.Name
End Function
   
v2
Comments
Richard MacCutchan 7-Nov-11 5:55am
   
Use <pre> tags around code!
Hi,
ur requirement is for comparing two documents than go for Open Source Compare tools which are available in net.
I suggest Beyond Compare just try its free for download
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900