簡體   English   中英

SharePoint:如何以編程方式將附件添加到列表項?

[英]SharePoint: How to add an attachment to a list item programatically?

我有以下代碼:

  SPList list = web.Lists[this.ListName];
  SPListItem item = list.Items.Add();

現在我想做的是:

   FileInfo[] attachments = attachmentDirectory.GetFiles();
        foreach (FileInfo attachment in attachments)
        {
           // Add the attachment from file system to the list item...

        }

如何將普通文件轉換為字節數組?

 foreach (FileInfo attachment in attachments)
        {
            FileStream fs = new FileStream(attachment.FullName , FileMode.Open,FileAccess.Read);

            // Create a byte array of file stream length
            byte[] ImageData = new byte[fs.Length];

            //Read block of bytes from stream into the byte array
            fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));

            //Close the File Stream
            fs.Close();

            item.Attachments.Add(attachment.Name, ImageData); 


        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM