0

我有一個可以將任何類型的文件作爲附件的SharePoint日曆事件。有沒有辦法訪問文件的內容/下載它們?我必須計算這些文件的校驗和。訪問SharePoint事件附件

+1

你應該重新標記您的問題和SharePoint 2007年或2003年,但不能在兩者之間是不同的。 – 2009-09-17 06:41:06

回答

3
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