Suppose you have a variable which is holding path to the
file including the filename along with the extension.
string
srcUrl = Target_Path_To_The_Directory + "\\FILE_NAME.doc";
|
Using the following code
you can upload file to the item of the SharePoint list
SPList list=SPContext.Current.Web.Lists[“LIST_NAME”];
SPListItem item=list.Items.Add();
FileStream fStream = File.OpenRead(srcUrl);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
item.Attachments.Add(filename, contents);
item.Update();
|
Hope this will help
Cheers
Pradeepa
Comments