As emerging knowledge management platforms, enterprise social media (ESM) provide an important way for employees to engage in knowledge sharing and information communication within their organization. However, the question of how to encourage employees to engage in continuous knowledge sharing rather than knowledge hiding on ESM has not received sufficient attention from scholars. In contrast to previous studies that focused on a single theory perspective and a single knowledge behavior, in this study, we took a user cognition and emotion perspective and constructed a mechanism model for the impact of knowledge sharing and knowledge hiding among employees on ESM based on social cognition theory and emotion as social information theory. A total of 240 valid questionnaires were collected and used to empirically test the model. The results indicate that reciprocity and outcome expectancy have a significant positive effect on employees’ knowledge-sharing behavior, while reciprocity and trust have a significant negative effect on employees’ knowledge-hiding behavior. Positive emotions play a positive (enhancing) moderating role on the path between outcome expectancy and knowledge-sharing behavior, while negative emotions play a negative (weakening) moderating role on the path between reciprocity and knowledge-hiding behavior, as well as between trust and knowledge-hiding behavior. By incorporating employee emotions into the framework of social cognition’s impact on employee knowledge behavior, this study enriches theories related to enterprise social media, knowledge management, and user behaviors. Our research findings have practical implications for guiding employees to engage in positive knowledge sharing and reducing knowledge hiding on enterprise social media.