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

unable to Attach file for list item using SP.File CopyTo Method

$
0
0

Requirement: I have a document library and list, the requirement is i need to take a document from document library and attach to list item in the list using CSOM only.

Followed technique: to achieve this requirement i followed below methodology

clientContext = SP.ClientContext.get_current();            
                webSite = clientContext.get_web();
                webSite.AllowUnsafeUpdates =true;
                var list = webSite.get_lists().getByTitle('Documents');
                item = list.getItemById(3);
                file = item.get_file();
                file.checkOut('Comments',1);
                file.copyTo("xxxxxxx/Lists/Student/Attachments/4/mahesh.docx","1"); 
file.checkIn('Comments',1);
                clientContext.load(file );
                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));      

Issue: This functionality is absolutely working fine when list item contains at least one attachment, if list item doesn't have any attachments the code is failing. i tried web.AllowUnsafeUpdates also but not working.

Could anyone please help me on this.... :(

Thanks in Advance!

Regards,

Mahesh Yamana


Mahesh@SharepointSolutions


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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