0

I've made simple console app to open office documents in free web version of office365. Source: https://github.com/Norrica/OfficeEmulator/blob/master/Program.cs

It just moves file to OneDrive folder and launches default browser with link as an argument. Link contains unique CID:

https://onedrive.live.com/sync?ru=https://d.docs.live.net/{CID}/{fileName}}

Currently, this CID is hard-coded in source, but I want usert to be able to set it once, on the first launch of my app.

TL;DR: How to achieve different behavior for the first launch of a console app?

Norica
  • 5
  • 1

1 Answers1

0

If it is just for this simple console app, you can add a string field to your class and prompt the user for input after launching the app. This will prompt the user every time he launches the app.

class Program
{
   string _cid;

   static void Main(string[] args)
   {
            ...    
      _cid = Console.ReadLine();
      // you can do some validations for the input here, and ask for another input if it's not valid
            ...
    }
}

If you want to prompt the user only the first time he launches the app, then you will need to store those values in a database, or in memory data store like redis etc. But considering that the app provided is some kind of exercise you can store it in a config for demonstration. Then you can lookup your storage for the user id, and if there is a present CID value for that user id, you'll know not to prompt the user for input again.

Now if you would like to know if it's the User's First time launching the app on that specific machine you will need to store additional information and do additional checks...

guxxo
  • 78
  • 7
  • I tried this solution, but it is not setting up the key, at least during debugging. Both ConfigurationManager.AppSettings["cid"] = cid; and ConfigurationManager.AppSettings.Set("cid", cid); Doesn't change App.config file – Norica Apr 12 '20 at 12:49
  • https://stackoverflow.com/questions/11149556/app-config-change-value Helped a lot. I consider this question fulfilled. – Norica Apr 12 '20 at 13:08