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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
chandrakanth uttara49 reputationPosted Jan 10, 2017, 12:19 AM EST
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
} );
}
}
}
Yahiya IqbalRank #3,312 · 434 reputationPosted Jan 10, 2017, 3:20 AM EST
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 uttara49 reputationPosted Jan 12, 2017, 3:17 AM EST
and the final url formed is as shown below.
Since i am new to this, i cannot understand what the error in URL
Yahiya IqbalRank #3,312 · 434 reputationPosted Jan 12, 2017, 6:27 PM EST
Yahiya IqbalRank #3,312 · 434 reputationPosted Jan 18, 2017, 10:08 PM EST
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());
} );