0

I have added a custom class to a Visual Studio solution. The solution has a number of features that are deployed and also has a aspx page that is deployed to the _layouts folder. In the Visual Studio project I can use the custom class in other .cs classes without referencing the namespace. But in the aspx page I cannot use a "using" statement to include my assembly namespace.

In the ASPX page I need to use/reference the code in my custom class as follows:

MyCustomClass CustomClass = new MyCustomClass();

When I import the namespace as follows in the ASPX page I get an error:

<%@ Import Namespace="MY.SOLUTION" %>

saying that the namespace cannot be imported.

How should I reference a custom class in a custom SharePoint aspx page?

  • When you add a layout page, you get a .cs file (code behind) with that. You need to write code there. – Nadeem Yousuf Feb 17 '15 at 11:55
0

I faced same problem, but now i resolved it. The main part of problem was that assemby which is created wit Visual Studio and deployed to sharepoint is not accessible by aspx created by sharepoint designer or another tool.

So you need to add reference to this assembly to aspx itself or webcofig of sharepoint site. If you would like to add it to aspx page you just need to put this code on top of file:

<%@ Register 
Tagprefix="MySolution" 
Namespace="MY.SOLUTION" 
Assembly="Solution, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxx"%>

So next question is where is public key. You can find it by sn.exe utility of windows SDK. Or by browsing folder: C:\Windows\assembly where you can find it by searching for assembly name (it is based on how you named it in Visual Studio).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.