Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string file1 = @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\CoreTouchDownApps\version.txt";
string file2 = @"C:\CoreTouchDownApps\version.txt";
if (string.Equals(file1, file2))
    try
    {
        Process.Start(@"C:\CoreTouchDownApps\CoreTouchDown.exe");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
    }

else
    try
Posted
Updated 5-Dec-15 1:56am
v2

You are comparing the files names, not the files contains.

You need to read the files contains and then compare the contains.
 
Share this answer
 
Comments
[no name] 5-Dec-15 8:05am    
Not really a solution, but a good hint at least, so a five.
Patrice T 5-Dec-15 8:09am    
Thank you
I know C# enough to understand what is wrong, but not enough to correct it myself. :)
You are comparing the paths to those files. What you need to do is to compare their content. Try this:
C#
string path1 = @"\\192.168.5.10\fbar\TOOLS\ProbingApps\ProbingSystem\CoreTouchDownApps\version.txt";
string path2 = @"C:\CoreTouchDownApps\version.txt";

string content1 = File.ReadAllText(path1);
string content2 = File.ReadAllText(path2);

if(content1 == content2)
{
    // do something
}
else
{
    // do something else
}

Please note that File.ReadAlltext()[^] reads the content of the file into memory. You shouldn't use this with big files.
 
Share this answer
 
v2
Comments
[no name] 5-Dec-15 8:03am    
And let's hope the files are not several GBs :). I let a five here.
Tomas Takac 5-Dec-15 8:11am    
Thanks. You are right, I updated the solution.
[no name] 5-Dec-15 8:35am    
Allow me a question from my side: For example 'ñ' has more than one representation in Unicode. What is now the safe way to compare text? Is it Operator == or is it the method compare?
Tomas Takac 5-Dec-15 17:00pm    
I'm not sure what you mean by "more than one representation in unicode". If that means different encoding then I would agree. The == operator does ordinal comparison (comparing character values). If you refer to culture-specific comparison then this only has effect on greater-than or less-than comparison (i.e. sorting). This does not affect equality/inequality hence ordinal comparison and == operator will work.
Tomas Takac 5-Dec-15 17:36pm    
ok, another idea. Are you talking about surrogate pairs? I guess that would be two different strings in either case. But I'd need to check that first to be sure.

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