I have a database table with columns like the serial number that is present in the SharePoint list, name of a file and path in which it is stored. That path is a directory path where the file is stored. I need to access that path and then get the image or document present in that path and then link it with the SharePoint list and then save it as an attachment. Could you please help me as how to access the path and then link it with the SharePoint list as I am new to SharePoint. It would be of great help if i could get any leads on this. Thanks.
Best How To :
The following code will help you add an attachment to a list item. Here I am getting a file from file system and adding it as an attachment to a list item.
using (var site = new SPSite("http://devspace/sites/Tester"))
using (var web = site.OpenWeb())
var list = web.Lists.TryGetList("Test List");
if (list != null)
var item = list.Items;
using (var fs = new FileStream(@"C:\TEmp\compass.jpg", FileMode.Open, FileAccess.Read))
byte fileData = new byte[fs.Length];
fs.Read(fileData, 0, System.Convert.ToInt32(fs.Length));