i wrote a below code to ease copytree but application not working well
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EPDM.Interop.epdm;
namespace Api_CopyTree
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private IEdmVault5 vault1 = null;
private void Form1_Load(object sender, EventArgs e)
{
try
{
vault1 = new EdmVault5();
IEdmVault8 vault = (IEdmVault8)vault1;
EdmViewInfo[] Views = null;
vault.GetVaultViews(out Views, false);
VaultsComboBox.Items.Clear();
foreach (EdmViewInfo View in Views)
{
VaultsComboBox.Items.Add(View.mbsVaultName);
}
if (VaultsComboBox.Items.Count > 0)
{
VaultsComboBox.Text = (string)VaultsComboBox.Items[0];
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnSelAssy_Click(object sender, EventArgs e)
{
try
{
ListBox.Items.Clear();
if (!vault1.IsLoggedIn)
vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
OpenFileDialog.InitialDirectory = vault1.RootFolderPath;
OpenFileDialog.Filter = "SOLIDWORKS Assembly (*.sldasm)|*.sldasm";
if (OpenFileDialog.ShowDialog() != DialogResult.OK)
return;
ListBox.Items.Add(OpenFileDialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void BrowseDestFolder_Click(object sender, EventArgs e)
{
try
{
listBox1.Items.Clear();
if (!vault1.IsLoggedIn)
vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
IEdmFolder10 folder =
(IEdmFolder10)vault1.BrowseForFolder(
this.Handle.ToInt32(),
"Select destination folder");
if (folder != null)
listBox1.Items.Add(folder.LocalPath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CopyTree_Click(object sender, EventArgs e)
{
try
{
if (ListBox.Items.Count != 1 || listBox1.Items.Count != 1)
{
MessageBox.Show("Select one assembly and one destination folder");
return;
}
// Ensure vault is connected
if (!vault1.IsLoggedIn)
vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
IEdmVault19 vault19 = (IEdmVault19)vault1;
string asmPath = ListBox.Items[0].ToString();
string destPath = listBox1.Items[0].ToString();
IEdmFolder5 parentFolder;
IEdmFile12 asmFile =
(IEdmFile12)vault19.GetFileFromPath(asmPath, out parentFolder);
if (asmFile== null|| parentFolder==null)
{
MessageBox.Show("Could not find the source file or folder in the vault.");
return;
}
// Fix: Properly intantiate the struct to clear default memory
EdmCopyTreeOptions options = new EdmCopyTreeOptions(); // Intializes all fields to Default Values
options.mbsPrefix = "Copy_";
options.mbsSuffix = "";
options.mbIncludeDrawings = -1; //-1 Means True in PDM COM API
options.mbUseLatestVersion = -1;
// Execute copy tree operation
vault19.CopyTree(
asmFile.ID,
parentFolder.ID,
destPath,
true,
true,
options,
this.Handle.ToInt32());
MessageBox.Show("Copy completed Successfully!");
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("PDM com Error: 0x"+ex.ErrorCode.ToString("X")+"\n"+ex.Message);
}
catch(Exception ex)
{
MessageBox.Show("General Error: " + ex.Message);
}
}
}
}