If there is a file in a document library in this structure:
How do I get the reference to DocumentSet from the file with server side object model?
You will need to break the URL apart. The item url is basically list/folder[x]/item.
Credits to Bunzab
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.