Click here to Skip to main content
15,886,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
C#
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

1 solution

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900