CopyIntoItems using an XML string

Sep 15, 2013 at 4:57 AM
Hi,

I have an XML string. I would like to create a file (XML) in a Share Point Library with this XML string, using SPService's CopyIntoItems method. Can anyone please help? The source url would be blank in this case and the XML string can be reasonably big size.
Coordinator
Sep 15, 2013 at 6:35 PM
venh123:

There's no need to post the same question multiple times. Someone in the SPServices community will get back to you when we can; you're not paying for support here.

Can you post the details of what you've tried so far?

M.
Sep 15, 2013 at 9:07 PM
Edited Sep 15, 2013 at 9:10 PM
Hi Marc,

Really sorry. I am not trying to post my questions multiple times. If it had happened by mistake, please excuse me. I was not sure, whether to post it as a question or an issue. Please excuse me. I really appreciate the work done by you and I am extremely thankful for your contribution to the community.

I did try to use a jQuery plugin (jQuery.base64.min.js) for converting my string to stream. The following is my sample XML, which I am trying to convert, so that I can create a file in a Share Point library and add the following content, using CopyIntoItems method. This XML is generated using another method. I have just given a sample here.

string str = "<SampleSets>
<SampleSet id="some_guid" Name="SS1">
<Sample id="some_guid" Name="S10">
<Sample id="some_guid" Name="SubS10"></Sample>
</Sample>
<Sample id="some_guid" Name="S20">
<Sample id="some_guid" Name="SubS20"></Sample>
</Sample>
</SampleSet>
<SampleSet id="some_guid" Name="SS2">
<Sample id="some_guid" Name="S11">
<Sample id="some_guid" Name="SubS11"></Sample>
</Sample>
<Sample id="some_guid" Name="S21">
<Sample id="some_guid" Name="SubS21"></Sample>
</Sample>
</SampleSet>
</SampleSets>"
var strm = $.base64.encode(str);
strm = strm.replace(/ /g, '');
$().SPServices({
    operation: "CopyIntoItems",
    webURL: webUrl,
    processData: false,
    async: false,
    SourceUrl: "",
    Stream: strm,
    DestinationUrls: [webUrl + "/Documents/FileName.xml"],
    completefunc: function (xData, Status) {
        debugger;
        alert("Status=" + Status + " XML=" + xData.responseXML.xml);
    }
});
Sep 15, 2013 at 11:38 PM
I have seen examples before that indicated that SourceUrl has to always be set (even though the MS documents don't say that). Just set it to some thing invalid, ex: http://null

Try that and see if it works.

Paul.


--

_________
Paul T

Sep 16, 2013 at 12:46 AM
Hi Paul,

Thanks a lot. It seems to be working. But I have a quick question. Is there any size restriction for the stream, using the CopyIntoItems method?
Sep 16, 2013 at 12:50 AM
Glad it's working.
I have not seen any limits called out specifically. But have seems words like 'of reasonable size'.


--

_________
Paul T

Sep 16, 2013 at 4:01 AM
Hi Paul,

Won't the CopyIntoItems method work in SP 2013 in the context of apps?
Sep 16, 2013 at 11:58 AM
It should work from 2013.



--

_________
Paul T

Coordinator
Sep 16, 2013 at 12:33 PM
CopyIntoItemsLocal is intended for copying an existing document into a new location. That's really the whole purpose of the Copy Web Service, as limited as it is.

I think what you want is UpdateListItems, as you are creating a new item.

M.
Sep 16, 2013 at 4:34 PM
Hi Paul,

It is giving me an access denied in jQuery-1.6.2.min.js file, though, in my App, I tried giving full control in appmanifest.xml. Not sure, whats going wrong?

Hi Marc,

Will UpdateListItems method create a new file? I saw some blogs, which are saying, this method won't create a new file. Also, MSDN documentation also talks only about creating a new list item, but not a file. I may be wrong. Can you please advise?

[http://social.msdn.microsoft.com/Forums/sharepoint/en-US/f135aaa2-3345-483f-ade4-e4fd597d50d4/add-document-to-library-via-listsupdatelistitems]

[http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems(v=office.12).aspx]
Sep 16, 2013 at 4:37 PM
Also, while using CopyIntoItems method in SP 2013 app, the Source / Destination URL will be the Host Web URL only and not the App Web URL, correct ?
Coordinator
Sep 16, 2013 at 4:53 PM
I have no idea how the SOAP Web Services will hold up in the 2013 app model. Is there some reason you aren't using CSOM?

M.
Sep 16, 2013 at 5:10 PM
Hi Marc,

My belief is that your library is much lighter, simpler and easier to use than CSOM. I am a big fan of your library and I love it. I will go for CSOM, only in the worst case, as my last option, since its complex and confusing, with much less documentation/support.
Sep 16, 2013 at 5:15 PM
Re: access denied in Jquery

Are you going cross domain? It sounds that way.
I have not worked with the app model, so I'm not sure either. It could be that your app is on a different domain?


--

_________
Paul T

Sep 16, 2013 at 5:36 PM
Yes Paul. App is on a different domain. Thanks for pointing that out. I think, I will have to use only CSOM here.
Coordinator
Sep 16, 2013 at 5:42 PM
Heh. I should send those comments to the SharePoint Product Group. ;+)

M.
Sep 17, 2013 at 12:27 AM
Marc,
Nah. I think this is an opportunity for a jquery library that wraps CSOM and makes it easy. Know anything about that type of thing?


--

_________
Paul T

Coordinator
Sep 18, 2013 at 4:09 AM
It's so tempting to wrap CSOM with simpler code. It really is.

M.