AnsweredAssumed Answered

C# PDM API - Batch Add Issue at File Creation Stage (Folder creates)

Question asked by Sean Donnelly on Apr 28, 2017
Latest reply on Apr 29, 2017 by Sean Donnelly

I'm back again, but things are going much easier these days for the most part thanks to all of the help here! Thanks again!

 

My issue this time is when I press the save button from a Winform to batch add. I'm using batch add because I read it's better to use it even if just one file. It makes it more flexible. I marked where the code breaks below. It does successfully create a folder, but fails to create the file. Any thoughts on what I'm doing wrong here? It breaks at the method buttonSave_Click() on line 91. Thanks again!

 

this is my error message:

 

using System;
using System.IO;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Windows.Forms;
using EPDM.Interop.epdm;


namespace InspectionTest
{
    public partial class InspectionForm : Form
    {
        private void InspectionForm_Load(object sender, EventArgs e)
        {
        }
        public InspectionForm()
        {
            InitializeComponent();
        }


        private IEdmVault5 vault1 = null;
        IEdmBatchAddFolders batchAddFolders;
        IEdmBatchAdd2 batchAdder;
        EdmFolderInfo[] ppoRetFolders = null;


        public void InspectionForm_Shown(Object sender, EventArgs e)
        {
            Activate();
        }


        private void buttonSave_Click(object sender, EventArgs e)
        {
            buttonSave.Enabled = false;
            labelStatus.Visible = true;


            IEdmVault7 vault2 = null;
            if (vault1 == null)
            {
                vault1 = new EdmVault5();
            }
            vault2 = (IEdmVault7)vault1;
            if (!vault1.IsLoggedIn)
            {
                vault1.LoginAuto("SeanVault", this.Handle.ToInt32());
            }


            string partNo = labelFileName.Text;
            string vaultRoot = vault2.RootFolderPath;
            string date = DateTime.Today.ToString("M-d-yy");
            string partNoRevDate = partNo + " Rev " + textRevision.Text + " " + date;
            string templatePath = vault2.RootFolderPath + @"\Templates\template.item.cvd";
            string newPath = @"Inspection Files\" + partNo + @"\" + partNoRevDate;
            string filename = partNoRevDate + ".insp";


            //setup variables
            IEdmFile5 templateFile = default(IEdmFile5);
            IEdmFolder5 templateFolder = default(IEdmFolder5);
            IEdmPos5 folderPos = default(IEdmPos5);
            IEdmFolder5 ppoRetParentFolder = default(IEdmFolder5);
            IEdmFile5 newFile = default(IEdmFile5);
            IEdmFolder5 srcFolder = null;
            


            templateFile = vault1.GetFileFromPath(templatePath, out ppoRetParentFolder);
            folderPos = templateFile.GetFirstFolderPosition();
            templateFolder = templateFile.GetNextFolder(folderPos);


            batchAdder = (IEdmBatchAdd2)vault2.CreateUtility(EdmUtility.EdmUtil_BatchAdd);
            batchAdder.AddFolderPath(vaultRoot + "\\" + newPath, 0, (int)EdmBatchAddFolderFlag.Ebaff_Nothing);
            
            batchAdder.AddFileFromVaultToPath(templateFile.ID, templateFolder.ID, vaultRoot + "\\" + newPath);


            EdmFileInfo[] ppoAddedFiles = null;


            // Commit all of the items in the batch to the vault
            //BREAKS HERE! ****************************
            batchAdder.CommitAdd(this.Handle.ToInt32(), ref ppoAddedFiles, (int)EdmBatchAddFlag.EdmBaf_Nothing);


            newFile = vault2.GetFileFromPath(vaultRoot + "\\" + newPath, out srcFolder);


            //update variables
            IEdmEnumeratorVariable10 myNewVars = default(IEdmEnumeratorVariable10); //Set the enumeratorvariable object  
            myNewVars = (IEdmEnumeratorVariable10)newFile.GetEnumeratorVariable(); //Cast the enumeratorvariable object to the file  


            myNewVars.SetVar("ITEM_RevisionNumber", "", textRevision.Text);
            myNewVars.SetVar("ITEM_DescriptionLine1", "", textDescription1.Text);
            myNewVars.SetVar("ITEM_DescriptionLine2", "", textDescription2.Text);
            myNewVars.SetVar("Comment-VersionFree", "", textComments.Text);
            myNewVars.SetVar("ITEM_StockingType", "", textStockingType.Text);


            myNewVars.CloseFile(false); //Always close the file when done accessing card variables to avoid runtime errors  
                                        //Mymessage = Mymessage + "File ID: " + myfile.ID + System.Environment.NewLine; //Create a message with the File ID  


            //Check-in new file
            newFile.UnlockFile(0, "Created and checked-in with Sean's API.");
            MessageBox.Show("Inspection Request Created. \r\n You will receive email confirmation shortly.");
            Dispose();
        }


        private void buttonCancel_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Request was cancelled");
            Dispose();
        }
    }
}

Outcomes