Wednesday, September 27, 2017

WCF REST Verbs


 REST is usually used with these HTTP verbs:
  • GET - retrieving items
  • POST - inserting items
  • PUT - updating items
  • DELETE - deleting items
You should never use GET for anything else then retrieving items. Using HTTP GET for data modification is considered as a bad practice in whole web development. To trigger GET you just need to create link on the web page or simply type a URL to the browser. You will hit refresh 50 times and you have 50 same inserts. Data modification should be always done with POST. If you have form which triggers HTTP POST (Post cannot be triggered directly) and you hit refresh browser will usually ask you if you want the form to be submitted again = if you really want to post and process the data again to the server.
Another problem is that GET request can be cached and redirected but POST requests cannot.

Monday, September 25, 2017

Get all files in directory C#

class Program
{
    static void Main()
    {
        // Get list of files in the specific directory.
        // ... Please change the first argument.
        string[] files = Directory.GetFiles("C:\\myDir\\",
            "*.*",          SearchOption.AllDirectories);

        // Display all the files.
        foreach (string file in files)
        {
            Console.WriteLine(file);
        }
    }
}