0

I have a default team site and want to create a new text file in it's document library programmatically.

SPList srcList = srcWeb.Lists["Documents"]

Returns a valid list. I can loop the listItems here,

foreach (SPListItem item in srcList.Items)

Get the File for each item and even the contents of each file.

However, even though I can get existing files, I cannot seem to create a new file in this list.

What I tried:

srcWeb.Folders["Documents"] - returns null

SPListItem destLI = srcWeb.Lists["Documents"].Items.Add(); - gives me a valid list item with a NULL .File. (Which I cannot initialize, since SPFile does not contructor).

srcWeb.Lists["Documents"].Folders.Add - I DO NOT want to create a new folder but simply add files to the root directory of the list.

POST technique (http://msdn.microsoft.com/en-us/library/ms454491(v=office.14).aspx) I'd rather avoid this because I will add Metadata in the future. Any ideas?

0

Finally, found it.

srcList.RootFolder.Files.Add was what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.