Used to download one or more attachments of a list item, optionally specifying filename.


resultset DOWNLOADATTACHMENT(string listName, int itemId, bool includeData, [string fileName = null]);

includeData: Boolean value that indicates if column Data is included in the results.

fileName: File name of attachment to download (optional).

Return value

The procedure returns a list of attachments with the following columns.

Column.NET Data TypeDescription
ServerUrl System.String The full server URL to the file
FileName System.String Filename of attachment including extension
ItemID System.Int32 The ID of the associated item in the list
Data System.Byte[] File content if includeData is true

Example: to download all attachments of item 12 in list Meals:

CALL DOWNLOAD('Meals', 12, true);

Example: to download the attachment with filename Recipe.doc of item 12 in list Meals:

CALL DOWNLOAD('Meals', 12, true, 'Recipe.doc');

Code examples

Download attachments

var connectionString = @";User=spuser;Password=******;Database=sitename;Authentication=Ntlm;";
using (var connection = new SharePointConnection(connectionString))
    using (var command = new SharePointCommand(@"CALL DOWNLOADATTACHMENT('Meals', 12, true)", connection))
        using (var reader = command.ExecuteReader())
            while (reader.Read())
                Console.WriteLine("Writing file: " + reader["FileName"].ToString());

                var data = (byte[])reader["Data"];
                System.IO.File.WriteAllBytes(@"c:\" + reader["FileName"].ToString(), data);

Code result

Writing file: Receipt.doc
Writing file: Image.png

Skip Navigation Links.

Visa     MasterCard