SPList oList = oWeb.Lists.TryGetList(LISTNAME);
SPListItem oItem = oList.Items.Add();
oItem["Title"] = "Sample text";
oItem.Update();
HttpFileCollection hfc = HttpContext.Current.Request.Files;
for (int iCount = 0; iCount < hfc.Count; iCount++)
{
{
HttpPostedFile hpf = hfc[iCount];
if (!String.IsNullOrEmpty(hpf.FileName))
{
Stream fStream = hpf.InputStream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
fStream.Dispose();
SPAttachmentCollection attachments = oItem.Attachments;
string fileName = Path.GetFileName(hpf.FileName);
attachments.Add(fileName, contents);
}
}
}
oItem.Update();
SPListItem oItem = oList.Items.Add();
oItem["Title"] = "Sample text";
oItem.Update();
HttpFileCollection hfc = HttpContext.Current.Request.Files;
for (int iCount = 0; iCount < hfc.Count; iCount++)
{
{
HttpPostedFile hpf = hfc[iCount];
if (!String.IsNullOrEmpty(hpf.FileName))
{
Stream fStream = hpf.InputStream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
fStream.Dispose();
SPAttachmentCollection attachments = oItem.Attachments;
string fileName = Path.GetFileName(hpf.FileName);
attachments.Add(fileName, contents);
}
}
}
oItem.Update();
No comments:
Post a Comment