الوصول شير حدث مرفق
-
08-07-2019 - |
سؤال
ولقد حدث شير التقويم الذي يمكن أن يكون أي نوع من الملفات كمرفق. هل هناك أي طريقة للوصول إلى محتويات الملف / تحميلها؟ لا بد لي من حساب مجموع الاختيار من هذه الملفات.
المحلول
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
لا تنتمي إلى StackOverflow