AnsweredAssumed Answered

EPDM Post Add file delete

Question asked by Matthew aDAMS on Dec 8, 2015

Morning all,


I have run into a little bit of a problem.  I have written an add-in that when a file is added to a folder it is renamed based on some user prompts.  I have everything working great, I was finishing up the add in with some error handling and house cleaning and have run into a problem.  The last step before renaming and moving the file is checking to see if the new file name ready exists. This works great until I handle the file already existing.  I display a message box starting the file already exists and then I want to delete the file being added.  This is where the problem come in.  I have tired to use IedmFile6 DeleteFile but I get an error that it can not find the file. I have also tried using System IO File.Delete, this produces no errors but does not delete the file.  I think the problem is the operation that is copying the file to the folder has not yet completed.  has anyone run into this or have any ideas of other things to try?  I have tried googling this but have not gotten anywhere with it.


Below is the section that handles the file new check, rename, move or delete. 

                    // Rename and move Added File
                    IEdmFile6 edmNewFile = (IEdmFile6)cEdmVault.GetObject(EdmObjectType.EdmObject_File, (int)fileID);
                    string Filename = edmNewFile.Name;
                    string wonumber = form.WO_Number;
                    string newfilename = wonumber + "-" + Filename;
                    if (File.Exists(newfilename))
                        edmNewFile.Rename(fileID, newfilename);
                        edmNewFile.Move(fileID, parentfolderID, edmNewFolder.ID, 0);
                        MessageBox.Show("File already exists!");
                        //File.Delete(fullpath);                                //No error but file is not deleted
                        edmNewFolder.DeleteFile(parentfolderID, fileID);      //Unable to find file


Thanks all,