9

I opened an empty sharepoint project in which I added a new application page. There I wrote some code. Now I need to enter that information under <SafeControls> tag in web.config file.

SafeControl Assembly="SharePointProject2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PublicKeyToken" Namespace="NamespaceOfYourProject" TypeName="*" Safe="True" />

So please suggest me how to find the PublicKeyToken for my application page.

Thanks & Regards,
Chandra Shekhar

7

You can use the sn tool to find the PublicKeyToken for your application. Simply build the assembly and use sn -T <assembly name>

If you are using SharePoint 2010 tooling you could also use $SharePoint.Project.AssemblyFullName$ In your code to insert the current assembly name at build time

  • Hello Tim. Thank u for the suggestion. So I need to navigate to Visual studio command prompt 2010 and type the above mentioned command right? So I should type sn-T myprojectname.dll. Is it right??? And I also dont understand "build the assembly" how to do that??? – Chandra Shekhar Jun 7 '11 at 10:59
  • Just command prompt should do - but the location of sn (which differs per machine) must be in the path. – Tim Ebenezer Jun 7 '11 at 11:00
  • So I should navigate to bin folder? – Chandra Shekhar Jun 7 '11 at 11:01
  • 2
    Hello, I found the solution for my answer. When you navigate to assembly folder there you will find .dll files just right click in the appropriate .dll file-> properties and there you can find the PublicKeyToken. Thanks – Chandra Shekhar Jun 7 '11 at 11:12
  • The $SharePoint.Project.AssemblyFullName$ answer from Tim is working very well too! No need to search for PuplicKeyToken – Gabriel Mongeon Jun 8 '11 at 20:46
1

If you want to do it directly in Visual Studio, follow this guide to set up the sn external tool.

1

You can get fully qualified name using below code.

Assembly asm = Assembly.LoadFrom(FileName);
asm.FullName.ToString()

I have created utility for this. You can find it here.

Thanks,

Ashish Chotalia

1

For information, you don't have to add a "safecontrol" entry in the web.config file if you use the standard SharePoint solution package (WSP) to deploy your page :

"safecontrol" entries will be automatically added by SharePoint when deploying the WSP.

  • Depending on your level of masochism, you will normally need to enter the SafeControls element into your manifest.xml which will be built into the solution. If you want to avoid said masochism, a tool like WSPBuilder will generate this for you. – James Love Jun 7 '11 at 21:52
0

An alternative solution, if your project is deployed to the server, is to use

gacutil /l SharePointProject2

From, for instance, the Visual Studio command prompt. You can then cut and paste the Public Key Token from the command window using the Mark tool. This prints the information about the assembly from the Global Assembly Cache.

  • 1
    Or you can go to the C:\Windows\assembly folder and copy the public key token from there. – Mihai Jun 7 '11 at 19:11
0

You can follow the blog here. http://faisalrafique.wordpress.com/2013/01/16/how-to-determine-an-assemblys-fully-qualified-name/

  • Welcome to SharePoint! While this may answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Kit Menke Jan 16 '13 at 21:24
0

You need to enter the 'FullName' of the Assembly into the 'Assembly'-Attribute of the SafeControl. Using PowerShell, you can get that 'FullName' with

[reflection.assembly]::LoadFrom("C:\Path\To\Assembly.dll").FullName

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.