UPLOADATTACHMENT

Used to upload an attachment to a list item.

Syntax

UPLOADATTACHMENT(string listName, int itemId, string fileName, byte[] data);

Example: to create a simple UTF-8 text file named helloworld.txt to list item 3 in list Files:

CALL UPLOADATTACHMENT('Files', 3, 'helloworld.txt', 'This is a small text file...');

Example: to upload binary content, such as a jpg image, simply use:

Upload attachment

var connectionString = @"Server=mysharepointserver.com;User=spuser;Password=******;Database=sitename;Authentication=Ntlm;";
using (var connection = new SharePointConnection(connectionString))
{
    connection.Open();
    using (var command = new SharePointCommand(@"CALL UPLOADATTACHMENT('Files', 3, 'bendsoft.jpg', @doc)", connection))
    {
        command.Parameters.Add("@doc", System.IO.File.ReadAllBytes(@"C:\bendsoft.jpg"));
        command.ExecuteNonQuery();
    }
}

Note! Uploading very large files to SharePoint will often require an unwanted amount of memory resources. To overcome this issue, it is recommended to use the streaming approach demonstrated below.

Example: to upload a large file on disk named 150Mb.bin using the streaming method, write:

Upload attachment stream input

var connectionString = @"Server=mysharepointserver.com;User=spuser;Password=******;Database=sitename;Authentication=Ntlm;";
using (var connection = new SharePointConnection(connectionString))
{
    connection.Open();
    using (var fs = System.IO.File.OpenRead(@"C:\150Mb.bin"))
    {
        using (var command = new SharePointCommand(@"CALL UPLOADATTACHMENT('Files', 44, '150Mb.bin', @doc)", connection))
        {
            command.Parameters.Add("@doc", fs);
            command.ExecuteNonQuery();
        }
    }
}


Skip Navigation Links.

Visa     MasterCard