Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

How to download list item attachment from display.aspx

$
0
0

Im uploading documentsto list item in list by using file upload control. Now I should download that file. I can able to insert documents into list item in attachment column which is predefined but am how can I download the attachments by clicking on the link in display.aspx.

I have written this for uploadFile controller.

            SPSite site = SPContext.Current.Site;
            SPWeb web = site.OpenWeb();

                    SPList list = web.Lists["list2"];
                    //SPListItem itemId = list.GetItemById(5);
            int itemId=3;
                    SPListItem newItem = list.GetItemById(itemId);
                    byte[] contents = null;

                    if (FileUpload1.PostedFile != null && FileUpload1.HasFile)
                    {
                        using (Stream fileStream = FileUpload1.PostedFile.InputStream)
                        {
                            contents = new byte[fileStream.Length];
                            fileStream.Read(contents, 0, (int)fileStream.Length);
                            fileStream.Close();

                        }
                        SPAttachmentCollection attachments = newItem.Attachments;
                        string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                        attachments.Add(fileName, contents);

                        newItem["CLMSAttachments"] = fileName;
                        newItem.Update();


                    }
Thanks in advance.




Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>