move files -javascript
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2012 11:37 PM
I am trying to move a document to a destination folder using javascript API.
The problem is if the document with same name already exists in the repository, the move does not work and throws error.
is there any way i can overwrite the document if it already exists through move api?
here is my code
var rootSpaceName = companyhome.childByNamePath("nodename");
var childList = rootSpaceName.children;
var count = childList.length;
var test = new Array();
for(var i=0; i
{
var childName = childList.properties.name;
var child = childList;
if(!child.isContainer)
{
var newSpace = childName.substring(0,4);
var ind = 0;
var existingSpace = rootSpaceName.childByNamePath(newSpace);
child.move(existingSpace) // this code fails if the document with same name already exists in the space
}
The problem is if the document with same name already exists in the repository, the move does not work and throws error.
is there any way i can overwrite the document if it already exists through move api?
here is my code
var rootSpaceName = companyhome.childByNamePath("nodename");
var childList = rootSpaceName.children;
var count = childList.length;
var test = new Array();
for(var i=0; i
{
var childName = childList.properties.name;
var child = childList;
if(!child.isContainer)
{
var newSpace = childName.substring(0,4);
var ind = 0;
var existingSpace = rootSpaceName.childByNamePath(newSpace);
child.move(existingSpace) // this code fails if the document with same name already exists in the space
}
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2012 03:37 AM
You can just check that if file exist delete the existing file.
add these piece of code
//check and remove existing file
var existing_file=existingSpace.childByNamePath(child.name);
if(existing_file!=null)
{ existing_file.remove();}
before this line
child.move(existingSpace)
add these piece of code
//check and remove existing file
var existing_file=existingSpace.childByNamePath(child.name);
if(existing_file!=null)
{ existing_file.remove();}
before this line
child.move(existingSpace)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2012 04:31 AM
thanks but unfortunately i can not do it.
if i delete then all the existing metadata and aspects of that file will be removed when i delete the file.
and the files that i am working with are PDFs.
if i delete then all the existing metadata and aspects of that file will be removed when i delete the file.
and the files that i am working with are PDFs.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2012 04:34 AM
You don't want to be using move then!
Sounds like you should be copying your node if target does not exist. Else just updating the content in your target node.
Sounds like you should be copying your node if target does not exist. Else just updating the content in your target node.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2012 04:46 AM
correct but updating content if its text file is easy. if the files are PDF, how can i ?
