473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compare two Documents using vb.net

seshu
156 New Member
Hi Everybody
I have a piece of code to compare two documents using vb.net but the problem here is it is comparing the whloe sentence but not word by word how to compare word by word

The code i wrote is like this

Expand|Select|Wrap|Line Numbers
  1. Dim objword As Word.Application
  2.         objword = CreateObject("Word.Application")
  3.         With objword
  4.             .Documents.Open("C:\Seshu is a bad boy.doc")
  5.             .ActiveDocument.Compare("C:\Seshu is a good boy.doc")
  6.             .ActiveDocument.SaveAs("C:\Seshu is a good11111 boy.doc")
  7.             .ActiveDocument.Close()
  8.         End With
Someone Please Help Me

Regards
Seshu
May 14 '07 #1
2 6009
vanc
211 Recognized Expert New Member
I got this piece of code some where and I think it should work fine with your issue
private bool FileCompare(string file1, string file2)
{
int file1byte;
int file2byte;
FileStream fs1;
FileStream fs2;

// Determine if the same file was referenced two times.
if (file1 == file2)
{
// Return true to indicate that the files are the same.
return true;
}

// Open the two files.
fs1 = new FileStream(file1, FileMode.Open);
fs2 = new FileStream(file2, FileMode.Open);

// Check the file sizes. If they are not the same, the files
// are not the same.
if (fs1.Length != fs2.Length)
{
// Close the file
fs1.Close();
fs2.Close();

// Return false to indicate files are different
return false;
}

// Read and compare a byte from each file until either a
// non-matching set of bytes is found or until the end of
// file1 is reached.
do
{
// Read one byte from each file.
file1byte = fs1.ReadByte();
file2byte = fs2.ReadByte();
}
while ((file1byte == file2byte) && (file1byte != -1));

// Close the files.
fs1.Close();
fs2.Close();

// Return the success of the comparison. "file1byte" is
// equal to "file2byte" at this point only if the files are
// the same.
return ((file1byte - file2byte) == 0);
}


cheers.
May 14 '07 #2
seshu
156 New Member
I dont know this C# or some other code more over i have a small doubt where is it saving the file which it is comparing
i mean at the end of the day i want three files
1-main file
2-file to be compared
3-file after comparision with first file but saved with different name and all the comparisions highlighted


Thank You

Regards
Seshu
May 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7690
by: Nasos Makriyiannis | last post by:
Hi, I'm new to XSL and I was wondering if there is a string-compare function available. I am using the following IF statement but it does not seem to be working: <xsl:if...
1
1899
by: Neil | last post by:
Folks, I've got a problem at work, and I'm hoping that someone out there may have had something similar (although I doubt it!) or may be able to offer some advice. I'm in the process of...
2
2409
by: Muqu | last post by:
hi, I am trying to compare one nicely written html file against another program generated one, whose formatting isn't very appealing to human eyes. I am tuning the code so that two htmls will...
2
2760
by: Ganesh Muthuvelu | last post by:
Hello, How can I compare or visually check the differences between two XML schemas. Let us say I have two files like "version_1.xsd" and "version_2.xsd" , how would I programtically find out the...
1
3345
by: Twinkle | last post by:
HI All, I have a problem..How to match two same word files. if someword missing in second files then it should be highlight by color change.
2
10425
by: =?Utf-8?B?SWtlciBMbGFub3M=?= | last post by:
I have to xml documents. I want to compare them and show them in two treeview controls. The one on the left is the new version of the document and the one is the right is the old version of the...
3
9537
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
1
1367
by: =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?= | last post by:
II want to compare how many seconds there are between files. If the files are within a 1 - 10 second range I want to copy them to their own folders. What I have so far is a couple methods that take...
2
5678
by: =?Utf-8?B?UFM=?= | last post by:
Hi, Is there a way to compare PDF, Word Document, Excel using C# like WinDiff utility that compares text file and display the result with the modified text in both the document? -- Thanks,...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.