upload a simple file to vault

オフライン

Hi everyone,

I try to make an app with aras.iom by C#. I want to upload a file to vault with code:

...

Item item_File_thumb = this.inn.newItem("File", "add");
item_File_thumb.setProperty("filename", myFilename);
item_File_thumb.attachPhysicalFile(myFilepath);

Item item_File_thumb_result = item_File_thumb.apply();

...

My app is stuck at apply() so it's not return any error.

Then, I try another way:

...

Item item_File_thumb = inn.newItem("File", "add");
item_File_thumb.setProperty("filename", myFilename);
item_File_thumb.setProperty("actual_filename", myFilePath);
item_File_thumb.setProperty("checkedout_path", myDir);
Item located = item_File_thumb.createRelationship("Located", "add");
located.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault

IomFactory factory = new IomFactory();
Aras.IOME.CheckinManager cm = factory.CreateCheckinManager(item_File_thumb);
Item result = cm.Checkin(1);

...

but it still not working. After Checkin(), everything is paused. because no return error so I do not know what's wrong.

Pls, help.

Parents
  • The Method is intended that you upload files to the Vault that are somewhere on the server. The folder in my example is some temporary folder I created at the C: drive. You normally just story files temporary there and immediately delete them after upload to the vault. The server Method will not work when you want to upload files from client side.

  • 0 オフライン in reply to AngelaIp

    I make a stand alone application with Aras API, it's not a server method. My file and path on local PC.

    • The path on local PC is correct.
    • The permission of item is enough 

    but it's still not working and no return error :(

  • Hello,

    As Angela has said, I'm not seeing anything wrong with your code itself. I tried running the same code in an IOM app on my local machine, and I was able to upload the file successfully. For reference, the exact code I used can be seen below:

    // Login variables defined above and intentionally left out of sample
    HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, database, username, password);
    Item res = conn.Login();
    // Make sure we logged in correctly
    if (res.isError())
    {
        Console.WriteLine("Could not log in");
        return;
    }
    // Upload the file
    Innovator inn = new Innovator(conn);
    Item file_upload = inn.newItem("File", "add");
    file_upload.setProperty("filename", "test.txt");
    file_upload.attachPhysicalFile(@"C:\Temp\test.txt");
    file_upload.apply();
    // Check that the file uploaded successfully
    if (file_upload.isError())
    {
        Console.WriteLine("Could not upload file");
    }
    // Let us know if the file uploaded successfully
    Console.WriteLine("File uploaded");

    This leads me to believe that the issue is not with your code itself. I think the issue might be that the computer permissions on the physical file itself might be preventing this upload. Could you try to check those permissions (in the Windows explorer, Right-click -> Properties -> Security)? Could you also try to upload the same file as the same user through the Innovator client?

    Chris

Reply
  • Hello,

    As Angela has said, I'm not seeing anything wrong with your code itself. I tried running the same code in an IOM app on my local machine, and I was able to upload the file successfully. For reference, the exact code I used can be seen below:

    // Login variables defined above and intentionally left out of sample
    HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, database, username, password);
    Item res = conn.Login();
    // Make sure we logged in correctly
    if (res.isError())
    {
        Console.WriteLine("Could not log in");
        return;
    }
    // Upload the file
    Innovator inn = new Innovator(conn);
    Item file_upload = inn.newItem("File", "add");
    file_upload.setProperty("filename", "test.txt");
    file_upload.attachPhysicalFile(@"C:\Temp\test.txt");
    file_upload.apply();
    // Check that the file uploaded successfully
    if (file_upload.isError())
    {
        Console.WriteLine("Could not upload file");
    }
    // Let us know if the file uploaded successfully
    Console.WriteLine("File uploaded");

    This leads me to believe that the issue is not with your code itself. I think the issue might be that the computer permissions on the physical file itself might be preventing this upload. Could you try to check those permissions (in the Windows explorer, Right-click -> Properties -> Security)? Could you also try to upload the same file as the same user through the Innovator client?

    Chris

Children
  • It's work! 

    The code is correct, the path is correct, file permission is enough. I missing package System.Data.HashFunction in my project.

    Thanks you Angelalp and Chris very much ^^

  • 0 オフライン in reply to DucTran

    Hii,  can You help me share ur code .I am using same code but getting error. below is the code in Aras-

    using System.Data.HashFunction();
    //var inn = this.newInnovator();
    //HttpServerConnection conn = IomFactory.CreateHttpServerConnection(url, database, username, password);
    {
    HttpServerConnection conn =
    IomFactory.CreateHttpServerConnection(""HDIVVI","innovator_regular","Admin@123");">localhost/.../Innovator.aspx","HDIVVI","innovator_regular","Admin@123");
    // Upload the file
    Innovator inn = new Innovator(conn);
    Item item_File_thumb = inn.newItem("File", "add");
    item_File_thumb.setProperty("filename", myFilename);
    item_File_thumb.setProperty("actual_filename", myFilePath);
    item_File_thumb.setProperty("checkedout_path", myDir);
    Item located = item_File_thumb.createRelationship("Located", "add");
    located.setProperty("related_id", "67BBB9204FE84A8981ED8313049BA06C"); // default vault
    IomFactory factory = new IomFactory();
    Aras.IOME.CheckinManager cm = factory.CreateCheckinManager(item_File_thumb);
    Item result = cm.Checkin(1);
    }
    ERROR: C8DE3EDD488C41F7BD10F99FA5ACDE82.
    Details in 6 temporary files
    C:\Program Files (x86)\Aras\Innovator\Innovator\Server\dll\ng5om2ao
    Line number 1, Error Number: CS1003, Syntax error, '(' expected
    Line number 1, Error Number: CS1026, ) expected