Search This Blog

Showing posts with label Attach File to ListItem. Show all posts
Showing posts with label Attach File to ListItem. Show all posts

Tuesday, November 8, 2011

Attach File to ListItem


public void AttachFileToListItem
(
string siteUrl,  
string webName, 
string listName,  
int itemId,  
string fileName, 
bool overwrite)
{
    using (ClientContext clientContext = new ClientContext(siteUrl))
    {
        FileStream fileStream = new FileStream(fileName, FileMode.Open);
        string attachmentPath = string.Format("/{0}/Lists/{1}/Attachments/{2}/{3}", 
webName, listName, itemId, Path.GetFileName(fileName));
        File.SaveBinaryDirect(clientContext, attachmentPath, fileStream, overwrite);
    }
}

Featured Posts

Unlock Hidden Windows Startup and Shutdown Details : How to Enable Verbose Startup and Shutdown Messages in Windows 11

WINDOWS TROUBLESHOOTING · FULL GUIDE Unlock Hidden Windows Startup and Shutdown Details Enable Verbose Status...