Hi apeawakening.
I don't know 100%, but I have come across similar problems in the past and it seemed to be related to the time it takes to create the file. We assume that the a given action returns then the actual action has completed but in reality, the action is a "request". This may mean that you "request" for a file to be created and then immediately try and create a link to it, before it has actually been created.
I solve the problem by sitting in an iterative loop, attempting to open the file - which will obviously fail, until the file has been fully created and committed. At that point, you can drop out of the loop and create the share.
Hope this helps
Mike