Hi, I receive the following error when I tried to create a new item to put
within a list:
"To add an item to a document library, use SPFileCollection.Add()"
From what I undestand, the SPFileCollection Add method is used to upload a
file in a document library, which is not what I want to do. I only want to
create an item and put a file as an attachment to it... How can I achieve
this?
Here is the code I am using:
SPSite mySiteCollection = new SPSite("http://myserver/mysite");
SPWeb mySite = mySiteCollection.RootWeb;
SPListItemCollection listItems = mySite.Lists["FromExchange"].Items;
SPListItem item = listItems.Add(); // Error is thrown here.
item["Title"] = "First Item";
item.Update();