Reputation: 133
I have a WinForm which connects to a OleDb. Whilst the Project (In Visual Studio 2010) was open i clicked on the New Menu and Said Add New Web Site
now the problem is i have a class which i created before adding the website - but the code-behind
file can't pick up that namespace or class example: (Note both projects are in the same solution)
namespace Name
{
//Code From The Original Project before Adding The WebSite
class DataAccessObject
{
private ...;
private ...;
}
}
public partial class Candidate : System.Web.UI.Page
{
...
...
...
DataAccessObject dao = new DataAccessObject();
}
The WebSite Section of the Project Does not even Pick up the NameSpace -
I have Also Tried
public partial class Candidate : System.Web.UI.Page
{
...
...
...
Name.DataAccessObject dao = new DataAccessObject();
}
EDIT
Also The whole idea behind this is that the user can switch between winForms and Web at will, So to pass on the DataAccessObject is required.
NOTE THIS IS THE VERY FIRST TIME I AM ENTERING THE WORLD OF ASP(.NET)
Any Advice
Upvotes: 0
Views: 580
Reputation: 73604
I assume the class is in the WinForms project. As far as I know, you can't add a reference to a WinForms application from an ASP.NET website. (I could be wrong on that, though.)
The usual pattern for having classes that are shared between projects is to have the classes in a separate Class Library project. Then, from the WinForms app and the ASP.NET website, you can add a reference, either to the project (if the project is in the same Solution) or the compiled .dll that the Class Library project generates.
Be sure the class is declared as Public, and you need to add the reference in Visual Studio.
Technically, you could get away with creating a .dll from the Class Library project and simply copying it into the \bin directory of the website, but from experience, it's better to have them in the same solution and add the project reference. This guarantees that the website always has the most recent version of the .dll.
There's a walk-though here and another related, helpful article here.
Upvotes: 1