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?

1
  • When you add a layout page, you get a .cs file (code behind) with that. You need to write code there. Commented Feb 17, 2015 at 11:55

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.