In some cases we need to add documents to the doument library programatically, the code snippet below demonstrates how to add a document to the document library .
using (SPSite objSite = new SPSite("urlAddress")) { objSite.AllowUnsafeUpdates = true; using (SPWeb oSPWeb = objSite.OpenWeb()) { oSPWeb.AllowUnsafeUpdates = true; //Test1 is the document library SPList docLibrary = oSPWeb.Lists["Test1"]; using (FileStream fs = File.OpenRead(FullPath)) { //Name is the name of the file SPFile file = oSPWeb.Files.Add(oSPWeb.Url.ToString() + "/" + docLibrary.Title.ToString() + "/" + Name, fs); file.Update(); } docLibrary.Update(); oSPWeb.AllowUnsafeUpdates = false; } objSite.AllowUnsafeUpdates = false; }