string url = "http://ABRLMOREMOSS/"; using (SPSite siteCollection = new SPSite(url)) { using (SPWeb spWeb = siteCollection.OpenWeb()) { SPList spList = spWeb.GetList(url); string fileName = "XXXX"; FileStream fileStream = null; Byte[] fileContent = null; try { string docPath =Server.MapPath("~/Excel/") + "Report2_Suppliers_OU_Invoice_DATE_HM_15_Dec_2012_1.xlsx"; //physical location of the file fileStream = File.OpenRead(docPath); fileContent = new byte[Convert.ToInt32(fileStream.Length)]; fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length)); spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true); spList.Update(); } catch (Exception ex) { } finally { if (fileStream != null) { fileStream.Close(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)