Programatically add file in folder in sharepoint Document Library
SPSite site = SPContext.Current.Site;
SPWeb oweb = site.OpenWeb();
oweb.AllowUnsafeUpdates = true;
SPList olist = oweb.Lists[listid];
SPListItem oitem = olist.GetItemById(Convert.ToInt32(itemid));
SPList list = oweb.Lists["SharedDocuments"];
SPFolder folder = list.RootFolder.SubFolders["Folder1"];
byte[] file = oitem.File.OpenBinary();
string dsturl = list.RootFolder.SubFolders["Folder1"].Url + "/" + oitem.File.Name;
SPFile myfile = folder.Files.Add(dsturl, file, true);
list.Update();