set attchment to a list in sharepoint 2013
if (ct.Attachment != null)
{
ct.DocumentName = ct.Attachment.ToString();
byte[] contents = GetFileStream();
if ((ct.DocumentName != null) && (contents.Length > 0))
{
SPAttachmentCollection fileAttach = empCertificationitem.Attachments;
if (ct.TemAttachmentName == System.IO.Path.GetFileName(ct.DocumentName))
{
empCertificationitem.Attachments.Delete(System.IO.Path.GetFileName(ct.DocumentName));
fileAttach.Add(ct.DocumentName, contents);
}
else
{
fileAttach.Add(ct.DocumentName, contents);
}
}
}
public byte[] GetFileStream()
{
Stream fStream = ct.stream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
return contents;
}
Comments