I am posting here a link to a discussion as it may be difficult to find it in the forum if you haven't read it before: since it is file I/O related, you may find it useful; the principles discussed there can be applied to your situation too. Look particularly to the last post from NickB and its sample project, which I consider very useful.