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.
B Loggins - 19 Mar 2008 15:19 GMT
> 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
[quoted text clipped - 9 lines]
> 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.
Justin Chase - 20 Mar 2008 14:37 GMT
> > 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
[quoted text clipped - 13 lines]
> 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.
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
> 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
[quoted text clipped - 6 lines]
> Thanks!
> Breckin
B Loggins - 21 Mar 2008 03:38 GMT
On Mar 20, 3:26 pm, "Michel LAPLANE \(MVP\)" <mich.lapl...@wanadoo.fr>
wrote:
> Just use a macro or addin to get the projectitem and change the property
> name, Visual studio do all the work :
[quoted text clipped - 21 lines]
> > Thanks!
> > Breckin
Doh! I didn't even think to try that, thanks!