The formation of three-dimensional sandpile was simulated by using discrete element model. The influence of sliding friction and rolling friction of particles on the formation of sandpile was discussed. The simulation results show that the angle of repose of sandpile is determined by both sliding friction and rolling friction. The trec-shaped microscopic mechanical structure in the sandpile was revealed by the simulation. The stress distribution at the bottom of sandpile was also obtained by the simulation. The simulation results show that when the angle of repose of sandpile is large, normal stress profiles with a clear stress dip near the center of the pile is generally formed, and when the angle of repose of sandpile is small, the maximal normal stress generally appears near the center of the pile. Which type of the stress distribution at the bottom of sandpile will emerge is rather accidental,depending on the real process of pileing.