This code snippet could be a good starter for your use case. Let me know, if that would work for you.