SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Adding new items to existing project in an Addin

Last post 10-28-2006 10:32 PM by GoMa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-27-2006 9:04 PM

    • itaibh
    • Top 25 Contributor
    • Joined on 10-01-2006
    • Israel
    • Posts 99

    Adding new items to existing project in an Addin

    Hi. I want to write an addin command that adds a file to a project. The code I tried didn't work:

     IProject p = ProjectService.CurrentProject;
     ProjectItem pi = new FileProjectItem(p, ItemType.Content);
     pi.Include = filename;
     pi.FileName = filename;
     p.Items.Add(pi);
     p.IsDirty = true

    where "filename" is the filename with no path (or relative path, for that manner).

    I also tried some variations of that code, but nothing worked.

    Can someone please direct me to the correct way of doing this?

    Thanks, Itai.
     

    Filed under: , , ,
  • 10-28-2006 10:17 AM In reply to

    Re: Adding new items to existing project in an Addin

    If you use p.Items.Add, the events for added items will not be fired. Use ProjectService.AddProjectItem(..) instead.

    Additionally, you have to refresh the projects pad: ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView(); 

    And as a last point: SharpDevelop never saves the projects when closing - projects are always saved immediately after the were modified, so call p.Save() instead of setting IsDirty. 

    Daniel Grunwald
  • 10-28-2006 7:14 PM In reply to

    • itaibh
    • Top 25 Contributor
    • Joined on 10-01-2006
    • Israel
    • Posts 99

    Re: Adding new items to existing project in an Addin

    Thanks, a project item was indeed added, however it points to the wrong direction...

    I set the Include property to the filename of the new item, and it added a relative path to the SharpDevelop bin directory. Surprisingly, it didn't help that I changed the filename to include the full path to the file...

    The file exists in the project directory. How do I set it in the project item correctly? And while at it, how do I open an item for viewing or editing? (basically, I want to programaticaly "open" the item using the default display binding of that item...)

     

  • 10-28-2006 9:52 PM In reply to

    • itaibh
    • Top 25 Contributor
    • Joined on 10-01-2006
    • Israel
    • Posts 99

    Re: Adding new items to existing project in an Addin

    Oops.. nevermind, my mistake... I set the full path to the include property instead of the filename property. It's working now :)

    The second problem is still valid... couldn't find a way to open the item I just created... 

  • 10-28-2006 10:32 PM In reply to

    • GoMa
    • Top 25 Contributor
    • Joined on 04-12-2006
    • Posts 80

    Re: Adding new items to existing project in an Addin

    I think you should use FileService.OpenFile().
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.