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

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

Installing And Exploring Auto Dark Mode Software

Windows Auto--Night--Mode: Simplify Your Theme Switching   Windows Auto--Night--Mode is a free and lightweight tool that makes switching bet...