Book a Demo

Author Topic: Element.Files.AddNew  (Read 3261 times)

Charlie

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Element.Files.AddNew
« 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?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Element.Files.AddNew
« Reply #1 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
« Last Edit: May 04, 2007, 04:14:03 am by Midnight »
No, you can't have it!

Charlie

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Element.Files.AddNew
« Reply #2 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();