Calendar appointment .ics location clickable

Today I’ve analyed a customer’s request about generating a calendar appointment (.ics file)

I discovered that mobile devices try to recgnise the event address and if they recognise it, they create a link to the related map.
Here are my tests:

Via Guglielmo Marconi, 123, 48018 Faenza RA
via Guglielmo Marconi, 48016 Faenza RA
via Guglielmo Marconi, 48016 Faenza
via Guglielmo Marconi, Faenza RA
via Guglielmo Marconi, 123 – Faenza RA
via Guglielmo Marconi – Faenza RA

via Guglielmo Marconi, Faenza
via Guglielmo Marconi Faenza
via Guglielmo Marconi – Faenza
Faenza RA, via Guglielmo Marconi
Faenza RA – via Guglielmo Marconi

Here a link about ics format:

Pubblicato in Uncategorized | Contrassegnato , , , , | Lascia un commento

Nice sites and apps to learn or improve your english

This is not a technical IT Post but it could be helpful to someone else.
In these months I’m improving my english language and here some interesting sites and apps that I used.

This site is very useful to practive you speaking skill.
Here you can find teachers or community teachers to practice your english with.
Usually the lesson has taken by skype

This site is similar to italki but I’ve never tried it, so I can only report it

Coniugazione Reverso
English has lots of irregular verb, this site could be useful to write the base form of the verb and get its coniugation

I found this great app/service (web application and mobile app)
It’s free (offline courses are available only paying), and there are lots of courses available in the website.
The way to teach and learn is the same used by duolingo so it’s very friendly and it really works fine (with me).
Using this app and adding some comunity courses I find the best way to learn vocabulary and prhasal verbs.
What I miss using this app is how to use what I learned, some example sentences, and here is the point where context reverso and become useful.
PS to find a course don’t set your native language because the search shows only the courses made in your language.
So even thought I’m italian and I’m interested in learning english, I setted English as my language otherwise I wouldn’t have found many important results.

Context reverso
Learning english include also learning phrasal verbs, prepositions and collocations.
Some times you learn the phrasal verb but It’s also important to check how to use it or having example sentences.
Here you can write something and get it traslated but the best thing is to get more sentences where the word is used.
Learning english include also learning phrasal verbs, prepositions and collocations.
Some times you learn the phrasal verb but It’s also important to check how to use it or having example sentences.

I don’t like it too much so I won’t talk about this application. However you can find lots of information on the Internet, because it’s very famous.
My suggestion is try it and take your consideration about it.

Pubblicato in Uncategorized | Contrassegnato , , , , | Lascia un commento

Error HTTPOnly cookies

I found this problem requesting a site by C#
Here an interesting link

I also invite you to read the documentation that I am quoting here for you:

If the server sends HTTPOnly cookies, you should create a System.Net.CookieContainer on the request to hold the cookies, although you will not see or be able to access the cookies that are stored in the container. If you do not create a container to hold the cookies, the request will fail. For more information on HTTPOnly cookies, see HTTPOnly cookies..

Pubblicato in .Net, c# | Lascia un commento

Pass json POST data to Web API method and enumerate it

This is a very tricky problem.
I had to create a REST service that receives any json class and elaborates its properties and values without knowing anything about the object received.

Here the body posted

{"lastName":"Regoli", "firstName":"Andrea"}

And here the REST service’s code

public HttpResponseMessage Post([FromBody]dynamic values, string templateName, string destFileName = null)
    // posted values {"lastName":"Regoli", "firstName":"Andrea"}
    foreach (JProperty x in (JToken)values)
        string name = x.Name;
        //JToken value = x.Value;
        string strValue = x.Value.Value<string>();

Another way to figure it out is receive a Dictionary but this means that the Json must be something like that


And here the REST service’s code

public HttpResponseMessage Post([FromBody]Dictionary<string,string> values, string templateName, string destFileName = null)
    // posted values {"lastName":"Regoli", "firstName":"Andrea"}
    foreach (string k in values.Keys)
        string name = k;
        string strValue = values[k];

Thery are quite different choose what you prefer or what you need.

Pubblicato in .Net, c#, REST | Contrassegnato , , | Lascia un commento

Store Dictionary object in config file

I found lots of solutions to solve this problem but I didn’t like many of them.
In this link I found THE solution:

To avoid to lose it in the future I’ve reported it as well:

      type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

     <add key="name1" value="value1" />
     <add key="name2" value="value2" />
     <add key="name3" value="value3" />
     <add key="name4" value="value4" />

How to use it:

using System.Collections.Specialized;
using System.Configuration;

public string GetName1()
    NameValueCollection section =
    return section["name1"];
Pubblicato in c# | Lascia un commento

POST Ajax and redirect file response to the browser

Yesterday a collegue of mine had a problem:
How post an ajax form and redirect the file result to the browser.
If you post a form to an handler that response with a file the result will be downloaded by your browser.
But how can we achive this behaviour via ajax?
We looked for a solution and we found something but not completed.
My collegue worked on this and here his result.
It’s written in javascript and not using jquery because jquery has some problems managing bynary response

function getFileFromHTTPRequest(modelForm, fileGenAction) {
    var xhr = new XMLHttpRequest();'POST', fileGenAction, true);
    xhr.responseType = 'blob';
    xhr.onload = function () {
        if (this.status === 200) {
            var filename = "";
            var disposition = xhr.getResponseHeader('Content-Disposition');
            if (disposition && disposition.indexOf('attachment') !== -1) {
                var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
                var matches = filenameRegex.exec(disposition);
                if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
            var type = xhr.getResponseHeader('Content-Type');

            var blob = new Blob([this.response], { type: type });
            if (typeof window.navigator.msSaveBlob !== 'undefined') {
                // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
                window.navigator.msSaveBlob(blob, filename);
            } else {
                var URL = window.URL || window.webkitURL;
                var downloadUrl = URL.createObjectURL(blob);

                if (filename) {
                    // use HTML5 a[download] attribute to specify filename
                    var a = document.createElement("a");
                    // safari doesn't support this yet
                    if (typeof === 'undefined') {
                        window.location = downloadUrl;
                    } else {
                        a.href = downloadUrl;
               = filename;
                } else {
                    window.location = downloadUrl;

                setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup
        } else if (this.status === 400)
            alert("The query returns too many elements, please select some filters.");
            alert("Can’t download the file. Error code: " + this.status);
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

How to use it by javascript

function getScreenElements() {
    getFileFromHTTPRequest($(".form-inline"), '@Url.Action("GetScreenElements")');

Here a sample of C# code to handle the request and response an excel file

public ActionResult GetScreenElements(SearchModel vm)
    using (var db = new EFContext())
        var count = db.GetElementsCount(vm.Parameter1, vm.Parameter2...);
        if (count &gt; 30000)
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request");
        var items = db.GetElements(vm.Parameter1, vm.Parameter2...).ToList();
        using (MemoryStream ms = new MemoryStream())
            var dtt = ConvertToDataTable(items);
            var wb = new XLWorkbook();
            wb.Worksheets.Add(dtt, "Elements");
            return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Octet, "Element List.xlsx");

#region Helper
private DataTable ConvertToDataTable(IList data)
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
    DataTable table = new DataTable();
    foreach (PropertyDescriptor prop in properties)
        table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
    foreach (T item in data)
        DataRow row = table.NewRow();
        foreach (PropertyDescriptor prop in properties)
            row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
    return table;
Pubblicato in .Net, Asp.Net, c#, MVC | Contrassegnato , , | Lascia un commento

Optimize Entity Framework performance

This wouldn’t be a complete article on how to improve EF performance but only a little reminder.
Every time you have performance problem on updating or adding entity these properties will help you.

public void SetOptimization()
    // this flag produce a huge performance change improvement
    this.Configuration.AutoDetectChangesEnabled = false;
    // turn off this flag increase little performance so my suggestion is do not turn it off
    this.Configuration.ValidateOnSaveEnabled = false; // I usually use it turned on

You can find a lot of articles about these properties so I suggest reading more in detailed article.
This is only a remind every time I forget the right properties’ names

Pubblicato in .Net, Entity Framework | Lascia un commento