How to Rename List Item attachments in sharepoint 2013/Sharepoint online ?
My Team gave options to use any of the below approach
-Using Javascript-REST/CSOM
-Using Sharepoint WorkFlows
-Using Sharepoint K2APPIT WorkFlows
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Yahiya IqbalPosted Jan 19, 2017, 3:08 AM
url : oDataUrl,
async: false,
type : 'POST',
headers : {
'accept' : 'application/json;odata=verbose',
'content-type' : 'application/json;odata=verbose',
'X-HTTP-Method' : 'PUT',
'X-RequestDigest' : $( '#__REQUESTDIGEST' ).val()
},
success : function() { alert('Attachment renamed'); },
fail :function(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
} );
Yahiya IqbalPosted Jan 12, 2017, 11:27 PM
chandrakanth uttaraPosted Jan 12, 2017, 8:17 AM
executor.executeAsync({/_api/SP.AppContextSite(@target)/web' ",


Since i am new to this, i cannot understand what the error in URLurl: "
/getfilebyserverrelativeurl('/Shared Documents/filename.docx')
/moveto(newurl='/Other Folder/filename.docx',flags=1)?@target='
method: "POST",
success: successHandler,
error: errorHandler
});
but iam getting Error as Bad Request -1002
and the final url formed is as shown below.
Yahiya IqbalPosted Jan 10, 2017, 8:20 AM
User Move file REST Call.
Folders of the attachment can be obtained in list path and ID of the item. So you will write a move call for that.
chandrakanth uttaraPosted Jan 10, 2017, 5:19 AM
data = data.d.results;
for ( var i = 0; i < data.length; i++ ) {
var oldName = data[i].FileName,
newName =oldName.substring(0,oldName.indexOf("."))+modified+oldName.substring(oldName.indexOf("."),oldName.length),//oldName + ' ' + modified,
oldUrl = data[i].ServerRelativeUrl,
newUrl = oldUrl.replace( oldName, newName ),
oDataUrl = siteUrl + "/_api/web/getfilebyserverrelativeurl('" + oldUrl + "')/moveto(newurl='" + newUrl + "', flags=1)";
//oDataUrl = siteUrl + "/_api/web/getfilebyserverrelativeurl('" + oldUrl + "')/copyto(newurl='" + newUrl + "',boverwrite=false)";
alert("@ 110 in renameAttachment data="+data+" oldName="+oldName+" newName="+newName+" oldUrl="+oldUrl+" newUrl="+newUrl+" oDataUrl="+oDataUrl);
$.ajax( {
url : oDataUrl,
async: false,
type : 'POST',
headers : {
'accept' : 'application/json;odata=verbose',
'content-type' : 'application/json;odata=verbose',
'X-HTTP-Method' : 'PUT',
'X-RequestDigest' : $( '#__REQUESTDIGEST' ).val()
},
success : function() { alert('Attachment renamed'); },
fail : failHandler
} );
}
}
}