I have a form on a .Net application page that allows a user to apply to multiple open positions at once with an attached resume.

I need to be able to attach the resume to each SP list item that is created. Each selected position creates a new row in the list.

*** I figured it out, I just haven't seen a solution online and wanted to see if others have a better solution. ***

1 Answer 1


First, I'm checking a GridView checkbox for Job Listings selected and loading them into an array.

bool atLeastOneRowSelected = false;
var IDs = new List<int>();

foreach (GridViewRow row in gvPositions.Rows)
    // Access the CheckBox
    CheckBox cb = (CheckBox)row.FindControl("cbJob");
    if (cb != null && cb.Checked)
        // Delete row! (Well, not really...)
        atLeastOneRowSelected = true;
        // First, get the ProductID for the selected row


Next, I create the SharePoint list items and save the internal ID into another array, which I will reference next to add the resume attachment.

List<int> intIDs = new List<int>();

SPList list = site.Lists["Candidates"];

SPListItem listItem = list.AddItem();


Once I've done that, I call the method to add the resume attachment to the above list items.

private void AddNewAttachment(List<int> NodeIDs)
    string destUrl = SPContext.Current.Site.Url;
    SPSite rootSite = new SPSite(destUrl);
    SPWeb site = new SPSite(destUrl).OpenWeb();
    site.AllowUnsafeUpdates = true;

    SPList myList = site.Lists["Candidates"];

    if (fileMUpload.PostedFile != null && fileMUpload.HasFile)

        Stream fStream = fileMUpload.PostedFile.InputStream;

        byte[] contents = new byte[fStream.Length];
        fStream.Read(contents, 0, (int)fStream.Length);

        string fileName = Path.GetFileName(fileMUpload.PostedFile.FileName);

        foreach (int NodeID in NodeIDs)

            SPListItem myNewItem = myList.GetItemById(NodeID);
            SPAttachmentCollection attachments = myNewItem.Attachments;

            attachments.Add(fileName, contents);

            myNewItem = myList.GetItemById(NodeID);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.