Quantcast
Viewing all articles
Browse latest Browse all 10096

Moving document from user mysite to another user mysite

Hi,

        I am creating Sharepoint 2013 app having requirement as mentioned below:

  1. Users in my site select document and can send it to another user
  2. When user select a document in mysite and sent it to another user, that document needs to be copied to another user's mysite.
  3. I can use REST API OR CSOM(Client object model) to do so...
  4. Step 1 is already achieved, I create ribbon button and on click i am giving people picker which can allow user to select another user to share.
  5. I am also getting my site url(Personal URL) of another user but whenever i am trying to copy to another user mysite document library it is not allowing me to copy as cross domain


Below is code snippet for copying file. I am able to move to same site but on another user mysite copyto function is not working.

function copyfiletoanotherusermysite() {

    context = new SP.ClientContext(appwebUrl);
    factory = new SP.ProxyWebRequestExecutorFactory(appwebUrl);
    context.set_webRequestExecutorFactory(factory);
    appContextSite = new SP.AppContextSite(context, hostwebUrl);
    var web = appContextSite.get_web();

    var notifyId;
    // Get Selected List & Item
    var currentLib = web.get_lists().getById(sourcelistid);
    var selectedItems = itemid;
    var count = CountDictionary(selectedItems);

    currentItem = currentLib.getItemById(selectedItems);
    context.load(currentItem, 'FileLeafRef');

    var _destinationlibUrl = SelectUserPersonalUrl + '/Destination' + '/' + docname;
    var File = currentItem.get_file();
    context.load(File);

    if (File != null) {
        alert(_destinationlibUrl);
        File.copyTo(_destinationlibUrl, true);

    }

    context.executeQueryAsync(function (sender, args) {
        notifyId = SP.UI.Notify.addNotification('Moving file...to      ' + _destinationlibUrl, true);
        //alert(notifyId);
    },
function (sender, args) {
    alert('Error occured' + args.get_message());
}
);
}

File.copyTo() function is working for same site domain but throwing error for another user mysite copying.

We can also use REST API instead of Client object model

Please help me to resolve this.

Regards,

Paras Sanghani


Thanks,

Paras Sanghani

http://parassanghani.blogspot.com/

Sharepointempower

Mark As Answer if it helped you.


Viewing all articles
Browse latest Browse all 10096

Trending Articles