Click here to Skip to main content
12,510,224 members (49,454 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C# C#4.0 SharePoint , +
public void Button1_Click(object sender, EventArgs e)
       {
           SPWeb mySite = SPContext.Current.Web;
           SPListItemCollection listItems = mySite.Lists["doneee"].Items;
           SPListItem item = listItems.Add();
 
           item.Update();
       }
       void documentAttachmentInSPList(SPListItem item)
       {
           SPListItem spListItem = item;
           string LISTNAME = spListItem.ParentList.Title;
           if (!string.IsNullOrEmpty(fileupload.FileName))
           {
               string fileExtension = fileupload.FileName.Substring(fileupload.FileName.IndexOf("*"));
               for (int i = 0; i < spListItem.Attachments.Count; i++)
               {
                   if ((spListItem.Attachments[i] != null)
                    && (spListItem.Attachments[i].Equals("FILENAME" + fileExtension)))
                   {
                       spListItem.Attachments.Delete("FILENAME" + fileExtension);
                       break;
 
                   }
               }
               spListItem.Attachments.Add("FILENAME" + fileExtension, fileupload.FileBytes);
               string attachmentURL = Request.Url.Scheme + "://" + Request.Url.Authority
               + "/Lists/" + LISTNAME + "/Attachments/" + spListItem.ID + "/";
               spListItem["Attached File"] = attachmentURL + "FILENAME" + fileExtension + ", View FILE";
 

           }


I created a button and fileupload control so that when i browse the file and click on button file should go intot the customlist.By using above code i am not able to upload file.
Posted 27-Nov-12 23:01pm
Kurac1866

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

And do you save your item then? (spListItem.SystemUpdate(false))
#JK
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 23 Oct 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100