private void UploadFileToList(SPListItem itemToAdd)
{
using (SPSite oSite = new SPSite(siteURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
if (fuOption.HasFile)
{
HttpFileCollection uploads = HttpContext.Current.Request.Files;
SPAttachmentCollection attachments;
for (int i = 0; i < uploads.Count; i++)
{
Stream fs = uploads[i].InputStream;
byte[] fileContents = new byte[fs.Length];
fs.Read(fileContents, 0, (int)fs.Length);
fs.Close();
attachments = itemToAdd.Attachments;
string fileName = Path.GetFileName(uploads[i].FileName);
attachments.Add(fileName, fileContents);
}
}
oWeb.AllowUnsafeUpdates = false;
}
}
}
{
using (SPSite oSite = new SPSite(siteURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.AllowUnsafeUpdates = true;
if (fuOption.HasFile)
{
HttpFileCollection uploads = HttpContext.Current.Request.Files;
SPAttachmentCollection attachments;
for (int i = 0; i < uploads.Count; i++)
{
Stream fs = uploads[i].InputStream;
byte[] fileContents = new byte[fs.Length];
fs.Read(fileContents, 0, (int)fs.Length);
fs.Close();
attachments = itemToAdd.Attachments;
string fileName = Path.GetFileName(uploads[i].FileName);
attachments.Add(fileName, fileContents);
}
}
oWeb.AllowUnsafeUpdates = false;
}
}
}