question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked SimpleSamples published

Calculator - C# 'If,Else' not working

Hi I created a calculator in c# and added this code: This code's functionality is that if the specified link contains the next version of the calculator (Example: If the website contains text "1.0.1" then the updater application should open) it should open the "Updater" form which I created. But the problem is that the below code is not working meaning even if the website does not contain the text "1.0.1" the updater form is opening on form load. I want the Updater form to only open when I change the text from "1.0.0" to "1.0.1". And if I don't change meaning that if the website text with 1.0.0, then the Updater form should not open and it should start up the original form (the calculator I built). Please help me if there's any mistake in the below code!

This is that website: https://pastebin.com/raw/Ujy28wcb

             WebClient webClient = new WebClient();
             if (!webClient.DownloadString("https://pastebin.com/raw/Ujy28wcb").Contains("1.0.1"))
             {
                 Updater frm = new Updater();
                     frm.Show();
             }
             else 
             {
                 Application.Restart();
    
             }

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

Hello,

Try the following

 var uri = "https://pastebin.com/raw/Ujy28wcb";
 var webClient = new WebClient();
 var content = webClient.DownloadString(uri);
 var expectedVersion = new Version("1.0.1");
    
 var version = new Version(content);
    
 if (version != expectedVersion)
 {
     Debug.WriteLine($"{content} is not {expectedVersion}");
 }
 else
 {
     Debug.WriteLine($"Yes {content} matches {expectedVersion}");
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SimpleSamples avatar image
0 Votes"
SimpleSamples answered SimpleSamples published

You say:

If the website contains text "1.0.1" then the updater application should open

It currently contains 1.0.0 so no update required, correct?

if the specified link contains the next version of the calculator ... it should open the "Updater" form

I reformatted that for clarity.

is not working meaning even if the website does not contain the text "1.0.1" the updater form is opening on form load

I am not sure what not working means. I am not sure if you are saying that the updater form should or should not open when the website has 1.0.0.

I want the Updater form to only open when I change the text from "1.0.0" to "1.0.1".

So you do not want the updater form to open when the website has 1.0.0.

if the website text with 1.0.0, then the Updater form should not open

So you do not want the updater form to open when the website has 1.0.0.

The website contains 1.0.0; it does not contain 1.0.1. Your code is saying that if the website does not contain 1.0.1 then update. Right?



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.