How to move pages between projects?

I have written quite a bit of db code in one web project and now want to copy a few of the aspx pages over to another VB.NET web project.  I am frustrated.  I copy the source files over to the new web project directory and then do an add existing to project.  The problem is that if I pull up the properties on the page, it shows the old project directory, not the new directory, where I put it and then added it from.  This caused debug to totally freak out and get lost.  I have gone through the source and changed all the references to the new project, to no avail.

There has to be a simple way to copy a page between projects and relink everything correctly.  Can anybody help?  
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sure, you can do it like this (assume your .aspx is named Form1):

1)  Go to the folder your files are stored in
2)  Select all 3 files associated with Form1
3)  Copy/Paste them, you should now see 3 files titled Copy of Form1
4)  Open your project solution, right click on the project name and say "Add Existing Item..."
5)  Scroll the selection box down to "All files (*.*)" and select the 3 files with the name Copy of Form1
6)  In your solution explorer locate the form you just added (Copy of Form1), right click on it and select "View Code"
7)  Change "Public Class Form1" to "Public Class Your_New_Name_Here"
8)  Save
9)  Right click on the form again, and select "Rename".  Rename the file to whatever name you want that isn't already taken.  The other 2 files will rename themselves to whatever you just picked.
10)  Rebuild the solution from the build menu.

Just out of curiosity, is this a bug or a configuration issue?

I had a solution open with one project in it.  I went to "add existing item" and browsed to a form in another completely separate solution/project.  

The solution with the "imported" page compiled fine, copied the imported aspx page, the codebehind and the resx file over and changed everything automatically to make it work with the new project.

..but obviously it didn't work for thhjr  or for your other posted link.
thhjrAuthor Commented:
That is EXACTLY what I do, but without the rename, since it is the name I want anyway.  I build and even exit the project and come back in.  Everything looks right until you right click on the page in the explorer and look at the full path to the page.  It still shows the old project's directory, and debug gets lost, using the wrong source file when you mark your break points.  You will even find both copies of the source on the tabbed menu, both the old and the moved files.  You don't really notice the problem until you modify one of the files and then you will click to put a break point at a particular place, the page refreshes and the breakpoint shows on a different place.

I will try the rename and see if it helps.  Maybe I can rename it, then rename it back.  Heck, I'm willing to try anything at this point.

OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

just something to try...
look in your projectName.vbproj it with notepad.
You'll see that every file in the project has 3 chunks in the .vbproj file like:
                    RelPath = "test2.aspx"
                    BuildAction = "Content"
                    RelPath = "test2.aspx.vb"
                    DependentUpon = "test2.aspx"
                    SubType = "ASPXCodeBehind"
                    BuildAction = "Compile"
                    RelPath = "test2.aspx.resx"
                    DependentUpon = "test2.aspx.vb"
                    BuildAction = "EmbeddedResource"

is the file you imported in vbproj? is it mapped to some other RelPath?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

It did work for the other link, and thus the answer got accepted.  If you view the last comment, it states that it works.  

I'm not sure if its a configuration issue or not, but this has always worked for me.

I didn't mean my comment to criticize or to imply your solution doesn't work. Not in the least bit!

I was criticizing  When an app has a function called "Add Existing Item" should...(you guessed it)  add an existing item....without all the extra work.

And I guess I should further say help with this question today, I ran a test using only "Add Existing Item" and it worked...and in the past, it has worked for the most part...but there have been occasions where I had to do something similar to your solution.

I mean, I've only had to do this a handful of times and with only one or 2 pages at a time...but if I really wanted to merge 2 full projects would be a PIA to have to follow 10 steps for each page.  MS should have made sure "Add existing item" worked more consistently...that's why I was wondering if you thought it was a config issue....

Take care,
thhjrAuthor Commented:
Well it appears to be a wierd bug.  The project directory is fine but when you import the new file, it still thinks it is supposed to be linked to the old directory.  As it turns out, it doesn't happen on every project.  Wierd.  It works on some projects, some times, and not others.

My workaround...which is just a slight variation of Torrwin's method is that I:
1. Add a new webform to the project with the same name of the page I want to import.
2. copy all the code on the original aspx page (except the page directive) and replace the new form's aspx code (except the page directive)
3. for codebehind, ctrl+a, ctrl+c the original page, then go to new codebehind, ctrl+a, ctrl+v to paste it all back.
thhjrAuthor Commented:
That is what I have been resorting to for several months. The hassle is that I have about 60 very complicated pages and I replicate this many times.  It gets real time consuming.
exactly my point! MS should have done a better job of this...I tested importing 4 more pages using only "Add Existing" and it worked, then page 5 caused build errors. Fixed using workaround, no build errs. Imported a 6th errors. Not cool!

VS.Net 2k5 is supposed to do away with a lot of these types of problems...let's pray it works.
thhjrAuthor Commented:
Sorry I haven't gotten back to this, but the problem isn't with cutting and pasting code, but rather that many of the pages have upwards to 50 graphics elements that need to be placed again.  Yes it appears to be a MS Bug.  On projects where I need to move a hundred pages, it can take two days.  This sucks.

I'm a Microsoft Partner, maybe I can rattle some cages via that route.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.