Question

J'ai un événement de calendrier SharePoint qui peut avoir n'importe quel type de fichier en pièce jointe. Est-il possible d'accéder au contenu du fichier / de le télécharger? Je dois calculer la somme de contrôle de ces fichiers.

Était-ce utile?

La solution

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();
        }

    }
}

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top