Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Charlie on May 04, 2007, 03:06:04 am

Title: Element.Files.AddNew
Post by: Charlie on May 04, 2007, 03:06:04 am
Hi,
I'm trying to add a file to an element.  However, using the code example below, the file is not saving.

Code: [Select]

private void AddFileToPackage(EA.Package package, string urlAddress)
{
....if (package != null)
....{
........if (package.Element != null)
........{
............package.Element.Files.AddNew(urlAddress, "Web Address");
............package.Element.Update();
............package.Update();
........}
....}
}


Anyone got any ideas what I'm doing wrong?
Title: Re: Element.Files.AddNew
Post by: «Midnight» on May 04, 2007, 04:10:59 am
You appear to be saving the element and package with .Update(), but not the file.

Try capturing the file to a variable, and then calling update on the variable. Something along the lines of:

(EA.File) foo = package.Element.Files.AddNew(urlAddress, "Web Address");
foo.Update();

David
Title: Re: Element.Files.AddNew
Post by: Charlie on May 04, 2007, 04:19:06 am
Great thanks...all working now.  C# code below:

Code: [Select]

EA.File file = package.Element.Files.AddNew(urlAddress, "Web Address") as EA.File;
file.Update();