Sharepoint 列表中 附件文件获取

Sharepoint 列表中 附件文件获取
SPSite site=new SPSite(url);

SPWeb web
=site.OpenWeb();

   SPList olist 
= web.Lists["最新通知"];

SPList nlist
= web.Lists["最新通知New"];
                SPListItem nitem 
= null;
                
foreach (SPListItem oitem in olist.Items)
                
{
                    
string title = oitem["标题"].ToString();

                         nitem 
= nlist.Items.Add();   //将附件内容存储到最新通知New中
                         nitem["标题"= oitem["标题"];
                        nitem[
"正文"= oitem["正文"];

                        
if (oitem.Attachments != null)
                        
{

                            SPAttachmentCollection attach 
= oitem.Attachments;
                            
for (int i = 0; i < attach.Count; i++)
                            
{
                                String url 
= attach.UrlPrefix + attach[i];
                                Console.WriteLine(
"正在下载{0}", url);
                                SPFile file 
= web.GetFile(url);
                                
byte[] content = file.OpenBinary();
                                nitem.Attachments.Add(oitem.Attachments[i].ToString(), content);
                            }


                        }

                        nitem.Update();

                 }

你可能感兴趣的:(SharePoint,sharepoint,url,byte,null,存储)