How to upload multiple files.

オフライン
I want to upload multiple files. I created the following method, but it does not work well. Where is it wrong? ************************************************************ //Aras Innovator 11.0 SP12 //Server side , c# Method Item fileObj1 = inn.newItem("File", "add"); fileObj1.setProperty("filename", "filename1.txt"); fileObj1.attachPhysicalFile(filepath1); fileObj1 = fileObj1.apply(); Item fileObj2 = inn.newItem("File", "add"); fileObj2.setProperty("filename", "filename2.txt"); fileObj2.attachPhysicalFile(filepath2); fileObj2 = fileObj2.apply();                       // <-- Here Innovator becomes busy. ************************************************************   Thank you.
Parents
  • Hi Sam, There are a few different approaches to accomplish this, but first I want to point out that you may have a problem with the definition of your file paths. Using the @ character before a string removes the need to escape slash characters. You should update your file path definitions to be like below.
    string filepath1 = @“C:\Aras\filename1.txt”;
    string filepath2 = @“C:\Aras\filename2.txt”;
    In terms of uploading multiple files, is there a particular reason you are creating File items directly like this? Typically, I would expect these files to be related to a Document or another ItemType. If you relate these Files to an item instead, you can upload multiple files using the sample below.
    Item doc = inn.newItem("Document", "add");
    doc.setProperty("item_number", "My doc");
    //First file
    Item docFile = doc.createRelationship("Document File", "add");
    docFile.setFileProperty("related_id", filepath1);
    // Second file
    Item docFile2 = doc.createRelationship("Document File", "add");
    docFile2.setFileProperty("related_id", filepath2);
    // Apply
    return doc.apply();
    If you need to upload these as File items without containers, I would recommend using the CheckinManager class which was built for this kind of use case. You can see an example of using this class below.
    Item fileUpload = inn.newItem("tmp");
    // File 1
    Item file1 = inn.newItem("File", "add");
    file1.setProperty("filename", "filename1.txt");
    file1.setProperty("actual_filename", filepath1);
    file1.setProperty("checkedout_path", @"C:\Aras");
    Item located = file1.createRelationship("Located", "add");
    located.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault
    fileUpload.appendItem(file1);
    // File 2
    Item file2 = inn.newItem("File", "add");
    file2.setProperty("filename", "filename2.txt");
    file2.setProperty("actual_filename", filepath2);
    file2.setProperty("checkedout_path", @"C:\Aras");
    Item located2 = file2.createRelationship("Located", "add");
    located2.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault
    fileUpload.appendItem(file2);
    // Apply
    fileUpload.removeItem(fileUpload.getItemByIndex(0));
    IomFactory factory = new IomFactory();
    Aras.IOME.CheckinManager cm = factory.CreateCheckinManager(fileUpload);
    return cm.Checkin(1);
    Chris
    Christopher Gillis Aras Labs Software Engineer
Reply
  • Hi Sam, There are a few different approaches to accomplish this, but first I want to point out that you may have a problem with the definition of your file paths. Using the @ character before a string removes the need to escape slash characters. You should update your file path definitions to be like below.
    string filepath1 = @“C:\Aras\filename1.txt”;
    string filepath2 = @“C:\Aras\filename2.txt”;
    In terms of uploading multiple files, is there a particular reason you are creating File items directly like this? Typically, I would expect these files to be related to a Document or another ItemType. If you relate these Files to an item instead, you can upload multiple files using the sample below.
    Item doc = inn.newItem("Document", "add");
    doc.setProperty("item_number", "My doc");
    //First file
    Item docFile = doc.createRelationship("Document File", "add");
    docFile.setFileProperty("related_id", filepath1);
    // Second file
    Item docFile2 = doc.createRelationship("Document File", "add");
    docFile2.setFileProperty("related_id", filepath2);
    // Apply
    return doc.apply();
    If you need to upload these as File items without containers, I would recommend using the CheckinManager class which was built for this kind of use case. You can see an example of using this class below.
    Item fileUpload = inn.newItem("tmp");
    // File 1
    Item file1 = inn.newItem("File", "add");
    file1.setProperty("filename", "filename1.txt");
    file1.setProperty("actual_filename", filepath1);
    file1.setProperty("checkedout_path", @"C:\Aras");
    Item located = file1.createRelationship("Located", "add");
    located.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault
    fileUpload.appendItem(file1);
    // File 2
    Item file2 = inn.newItem("File", "add");
    file2.setProperty("filename", "filename2.txt");
    file2.setProperty("actual_filename", filepath2);
    file2.setProperty("checkedout_path", @"C:\Aras");
    Item located2 = file2.createRelationship("Located", "add");
    located2.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault
    fileUpload.appendItem(file2);
    // Apply
    fileUpload.removeItem(fileUpload.getItemByIndex(0));
    IomFactory factory = new IomFactory();
    Aras.IOME.CheckinManager cm = factory.CreateCheckinManager(fileUpload);
    return cm.Checkin(1);
    Chris
    Christopher Gillis Aras Labs Software Engineer
Children
  • Looking to adapt this for uploading from 20 to 1000 files as we migrate from the older PLM Systems to Aras

    Examples I've seen require "related_id" leading me to believe this would be a two-step process. 

    Batch load document information, pull "related_id" and then build .cs to upload physical file (.pdf)

    Does Aras facilitate the multi-file upload/migration?  Is there an admin tool to address this?