To show a NetDiagram diagram inside a SharePoint page:
- Write a custom WebPart for SharePoint by inheriting from the ASP.NET WebPart class.
- Create an instance of the DiagramView class.
- Set the ClientSideMode property to Canvas or ImageMap.
- Deploy MindFusion.Diagramming.js and ImageGen.* files to the Web server outside of SharePoint.
- If ClientSideMode is set to Canvas, set the JsLibraryLocation property as a string specifying the path to MindFusion.Diagramming.js.
- If ClientSideMode is set to ImageMap, set the ImageGenLocation property to point to the ImageGen.* files.
WebPart code
Copy Code
|
---|
namespace DiagramWebPart { public class DiagramViewPart : WebPart { public DiagramViewPart() { diagramView = new DiagramView(); diagramView.ClientSideMode = ClientSideMode.Canvas; diagramView.JsLibraryLocation = @"http://yoursite.com/MindFusion.Diagramming.js"; Controls.Add(diagramView); } public DiagramView DiagramView { get { return diagramView; } } private DiagramView diagramView; } } |
- Add the AllowPartiallyTrustedCallers attribute (located under the System.Security namespace) to the AssemblyInfo.cs file:
AssemblyInfo.cs
Copy Code
|
---|
[assembly: AllowPartiallyTrustedCallers()] |
To deploy Your WebPart in the SharePoint server, perform the next steps:
- Give your assembly a strong name.
- Find the public key token for your assembly.
- Locate the SharePoint Web application in which you want to deploy this WebPart. You can do this by using the IIS Manager under administrative tools.
- Drop the DLL in the _app_bin directory into the virtual directory.
Find Web.Config under the same virtual directory and add the following to the SafeControls section, replacing the PublicKeyToken value with the one of your assembly:
Web.Config
Copy Code
|
---|
<SafeControl Assembly="DiagramWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d81b2da0f7305ec3" Namespace="DiagramWebPart" TypeName="DiagramViewPart" Safe="True" /> |
- Open your browser, go to the Web application whose virtual directory you are using.
- Select Site Actions -> Site Settings -> Modify All Site Settings.
- Click on "Web Parts" under Galleries.
- Click on "New" in the toolbar, and find the DiagramWebPart.DiagramViewPart.
Mark the checkbox, go to the top, and click on "Populate Gallery".
You should see the DiagramViewPart.webpart file ready to use in your site.
To add the new DiagramViewPart to a page, perform the following steps:
- Go to the site of your choice and click on Site Actions -> Edit Page. By using this option, you can add, delete or update new WebParts on this page.
- Click the "Add a WebPart" button on any one of the WebPart zones.
- Check the checkbox for DiagramViewPart, and click "Add".
You should now see the DiagramViewPart running under SharePoint.