Link to home
Start Free TrialLog in
Avatar of thhjr
thhjr

asked on

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?  
Avatar of Torrwin
Torrwin
Flag of United States of America image

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.

https://www.experts-exchange.com/questions/21428519/Best-way-to-copy-an-aspx-vb-file.html
Torrwin,

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, vs.net 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.
Avatar of thhjr
thhjr

ASKER

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.

ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Samtran,

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.
Torrwin,

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

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

And I guess I should further say that...to 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 together...it 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,
Sam
Avatar of thhjr

ASKER

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.



thhjr,
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.
Avatar of thhjr

ASKER

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 page...build errors. Not cool!

VS.Net 2k5 is supposed to do away with a lot of these types of problems...let's pray it works.
Avatar of thhjr

ASKER

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.