代码之家  ›  专栏  ›  技术社区  ›  Prabhu

访问SharePoint事件附件

  •  0
  • Prabhu  · 技术社区  · 15 年前

    我有一个SharePoint日历事件,可以将任何类型的文件作为附件。有没有办法访问文件的内容/下载它们?我必须计算这些文件的校验和。

    1 回复  |  直到 15 年前
        1
  •  3
  •   Kit Menke    15 年前
    string siteURL = "http://yourserver/yourpathtothesite";
    using (SPSite site = new SPSite(siteURL))
    {
        using (SPWeb web = site.OpenWeb())
        {
            string listName = "Events";
            SPList calendarList = web.Lists[listName];
    
            // get whatever item you are interested in
            SPListItem item = calendarList.GetItemById(1);
    
            foreach (String attachmentname in item.Attachments)
            {
                String attachmentAbsoluteURL = item.Attachments.UrlPrefix + attachmentname;
    
                // To get the SPSile reference to the attachment just use this code
                SPFile attachmentFile = web.GetFile(attachmentAbsoluteURL);
    
                // To read the file content simply use this code
                Stream stream = attachmentFile.OpenBinaryStream();
                StreamReader reader = new StreamReader(stream);
                String fileContent = reader.ReadToEnd();
            }
    
        }
    }
    

    来源: http://www.dotnetking.com/TechnicalComments.aspx?LogID=352