0

i'm trying to figure out how to fill value in Document Library column using web part. Now im using this code to add value in Task List column using this code. I'm looking solution on how to use something simillar to add value in Document Library Column. Examples and Suggestion will be much appreciated. Thanks and Regards.

SPWeb oWeb = SPContext.Current.Web;

SPListItemCollection listItems = oWeb.Lists["DDC"].Items;

SPListItem oItem = listItems.Add();

oItem["Title"] = "New Task";

oItem.Update();
4

1 回答 1

1

请参考以下代码:

SPWeb oWeb = SPContext.Current.Web;
SPList lstTarget = oWeb.Lists.TryGetList("DDC");

Hashtable metaData = new Hashtable();

metaData.Add("Field1 Name", "Field1 Value");
metaData.Add("Field2 Name", "Field2 Value");
metaData.Add("Field3 Name", "Field3 Value");

byte[] bytes = File.ReadAllBytes("c:\folder\myfile.txt"); //Set path to file to be uploaded in document library.

oWeb.AllowUnsafeUpdates = true;
SPFile destfile = lstTarget.RootFolder.Files.Add("myfile.txt", bytes, metaData, true);
oWeb.AllowUnsafeUpdates = false;
于 2012-12-31T06:45:12.077 回答