Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Tue, 18 Mar 2008 20:26:32 -0700 (PDT),    group: microsoft.public.vstudio.extensibility        back       


How do you rename project items programmatically?   
Let's say I have a project with file "c:\foo\bar.cs" and I want to
point that project item to a new name ("c:\bar\baz.cs").  I don't want
to use SaveAs, because the new file may already exist.

One way to do that is to remove the old item and add the new one, but
that has some undesirable effects.  Is there any way to do this using
the SDK or Automation objects?

Thanks!
Breckin
date: Tue, 18 Mar 2008 20:26:32 -0700 (PDT)   author:   B Loggins

Re: How do you rename project items programmatically?   
Well all you're doing is basically renaming a file and if the file
already exists then no matter the method you choose you're going to
have the same problems. You either prompt the user to overwrite
"baz.cs" or you would give it some name such as "baz2.cs". If you want
to know if the file already exists just use some code such as:

if(File.Exists(path))
   path = Path.GetDirectoryName(path) + "baz2.cs";

SaveAs(path);

Alternately you could prompt the user to overwrite the other file
instead.
date: Wed, 19 Mar 2008 06:10:56 -0700 (PDT)   author:   Justin Chase

Re: How do you rename project items programmatically?   
On Mar 19, 8:10 am, Justin Chase  wrote:
> Well all you're doing is basically renaming a file and if the file
> already exists then no matter the method you choose you're going to
> have the same problems. You either prompt the user to overwrite
> "baz.cs" or you would give it some name such as "baz2.cs". If you want
> to know if the file already exists just use some code such as:
>
> if(File.Exists(path))
>    path = Path.GetDirectoryName(path) + "baz2.cs";
>
> SaveAs(path);
>
> Alternately you could prompt the user to overwrite the other file
> instead.

True.  I guess what I was looking for was a method to have a project
item "point" to another file that already exists on disk.  I know it's
a weird workflow, just seeing if it's possible.
date: Wed, 19 Mar 2008 07:19:05 -0700 (PDT)   author:   B Loggins

Re: How do you rename project items programmatically?   
On Mar 19, 8:19 am, B Loggins  wrote:
> On Mar 19, 8:10 am, Justin Chase  wrote:
>
> > Well all you're doing is basically renaming a file and if the file
> > already exists then no matter the method you choose you're going to
> > have the same problems. You either prompt the user to overwrite
> > "baz.cs" or you would give it some name such as "baz2.cs". If you want
> > to know if the file already exists just use some code such as:
>
> > if(File.Exists(path))
> >    path = Path.GetDirectoryName(path)  "baz2.cs";
>
> > SaveAs(path);
>
> > Alternately you could prompt the user to overwrite the other file
> > instead.
>
> True.  I guess what I was looking for was a method to have a project
> item "point" to another file that already exists on disk.  I know it's
> a weird workflow, just seeing if it's possible

You could read the contents of the new one, write it to the old one
then save it.

You could add the new one, remove the old one, then rename the new
one.

Those are some other ideas.
date: Thu, 20 Mar 2008 06:37:29 -0700 (PDT)   author:   Justin Chase

Re: How do you rename project items programmatically?   
Just use a macro or addin to get the projectitem and change the property 
name, Visual studio do all the work :
    in C#
    //get the project in the projects collection of the solution using a 
Solution2 object
    solution.Projects
    // Get the projectitem in the ProjectItems collection of the project 
using a Project object
    project.ProjectItems
    // change the property Name of the ProjectItem Object
    projectItem.Name = "NewName"
    // Vs change the item name and the file name automatically

Enjoy with VS
"B Loggins"  a écrit dans le message de 
news:cfa361b9-2c6f-44d3-8a47-36dbfff8102c@2g2000hsn.googlegroups.com...
> Let's say I have a project with file "c:\foo\bar.cs" and I want to
> point that project item to a new name ("c:\bar\baz.cs").  I don't want
> to use SaveAs, because the new file may already exist.
>
> One way to do that is to remove the old item and add the new one, but
> that has some undesirable effects.  Is there any way to do this using
> the SDK or Automation objects?
>
> Thanks!
> Breckin
date: Thu, 20 Mar 2008 21:26:58 +0100   author:   Michel LAPLANE \(MVP\)

Re: How do you rename project items programmatically?   
On Mar 20, 3:26 pm, "Michel LAPLANE \(MVP\)" 
wrote:
> Just use a macro or addin to get the projectitem and change the property
> name, Visual studio do all the work :
>     in C#
>     //get the project in the projects collection of the solution using a
> Solution2 object
>     solution.Projects
>     // Get the projectitem in the ProjectItems collection of the project
> using a Project object
>     project.ProjectItems
>     // change the property Name of the ProjectItem Object
>     projectItem.Name = "NewName"
>     // Vs change the item name and the file name automatically
>
> Enjoy with VS
> "B Loggins"  a écrit dans le message denews:cfa361b9-2c6f-44d3-8a47-36dbfff8102c@2g2000hsn.googlegroups.com...
>
> > Let's say I have a project with file "c:\foo\bar.cs" and I want to
> > point that project item to a new name ("c:\bar\baz.cs").  I don't want> > to use SaveAs, because the new file may already exist.
>
> > One way to do that is to remove the old item and add the new one, but
> > that has some undesirable effects.  Is there any way to do this using
> > the SDK or Automation objects?
>
> > Thanks!
> > Breckin

Doh!  I didn't even think to try that, thanks!
date: Thu, 20 Mar 2008 19:38:13 -0700 (PDT)   author:   B Loggins

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us