Liquid entrapment over patterned surfaces has applications in diagnostics, oil recovery, and printing processes. Here we study the process of oil displacement upon sequential injection of water over a photopatterned structure in a confined geometry. By varying the amplitude and frequency of triangular and sinusoidal patterns, we are able to completely remove oil or trap oil in varying amounts. We present a theoretical model based on geometrical arguments that successfully predicts the criterion for liquid entrapment and provides insights into the parameters that govern the physical process.