<asp:FileUpload ID="FileUploadAttachment" runat="server" />
And in your update function, you can upload the attachment by:
SPListItem studentDetailsItem = SPContext.Current.Web.Lists["Student Details"].Items.Add();
studentDetailsItem["StudentID"] = Guid.NewGuid();
studentDetailsItem["FirstName"] = txtFirstName.Text;
studentDetailsItem["LastName"] = txtLastName.Text;
//------------------------------------------------------------
// If file selected, save to list
if (FileUploadAttachment.HasFile == true)
{
SPAttachmentCollection attach = studentDetailsItem.Attachments;
String fileName = FileUploadAttachment.PostedFile.FileName;
byte[] textfile = FileUploadAttachment.FileBytes;
attach.Add(fileName, textfile);
}
// ------------------------------------------------------------
studentDetailsItem.Update();
And in your update function, you can upload the attachment by:
SPListItem studentDetailsItem = SPContext.Current.Web.Lists["Student Details"].Items.Add();
studentDetailsItem["StudentID"] = Guid.NewGuid();
studentDetailsItem["FirstName"] = txtFirstName.Text;
studentDetailsItem["LastName"] = txtLastName.Text;
//------------------------------------------------------------
// If file selected, save to list
if (FileUploadAttachment.HasFile == true)
{
SPAttachmentCollection attach = studentDetailsItem.Attachments;
String fileName = FileUploadAttachment.PostedFile.FileName;
byte[] textfile = FileUploadAttachment.FileBytes;
attach.Add(fileName, textfile);
}
// ------------------------------------------------------------
studentDetailsItem.Update();
No comments:
Post a Comment