向SPS列表中添加附件
怎样向一个列表添加附件呢?
查了很多资料,最后在wss的SDK上找到答案。
代码如下:
PSite site = SPContext.Current.Site;
SPWeb srcSite = site.AllWebs["Site_Name"];
SPFile file = srcSite.Folders["Folder_Name"].Files["File_Name"];
SPList list = srcSite.Lists["Announcements"];
SPListItem listItem = list.Items[5];
SPAttachmentCollection attachments = listItem.Attachments;
string fileName = file.Name;
byte[] binFile = file.OpenBinary();
attachments.Add(fileName, binFile);
listItem.Update();