Posted by Shantha Kumar on 31st March 2008

Uploading File from Local Machine to SharePoint ListItem as an attachment

To attach the file from Local Machine to SharePoint ListItem as an attachment, Import the System.IO namespace to use the Stream Class to read the file contents.

Use System.Web.UI.WebControls.FileUpload control is named as fileUpload in code.
Sample code for uploading the file from Local Machine to ListItem attachments as follows,
//Check the FileUpload control has the file
if (fileUpload.PostedFile [...]