Welcome to EMC Consulting Blogs Sign in | Join | Help

Kalpesh Prajapati

Using ASP.NET Web Part into MOSS 2007 Web Site - Just Export and Import

You can reuse ASP.NET Web Parts in your MOSS Web Site by exporting them to create .webpart files, which are XML files that contain details about your Web Part. To enable export functinality you need to do some modifications to your Web Part code and your configuration settings.

After you have a .webpart file, you can import it into any MOSS Web Site.

Step 1: To export an ASP.NET Web Part

1.    In your Web Part code, set the ExportMode property to allow properties to be exported. In the following code, we set the value to All, which allows sensitive properties to be exported.
this.ExportMode = WebPartExportMode.All;

2.    Modify the <system.web> section of the web.config file as follows:
<system.web> <webParts enableExport ="true"/> </system.web>

3.    From the Web Part menu, choose Export to create a .webpart file you can import into a Windows SharePoint Services Web Part Page.
Save file on Disk. Let’s say file name is mywebpart.webpart Please not you may get some security warning about properties set for the Web Part. Reset properties if you do not want this values to be exported.

Step 2: To import a mywebpart.webpart file into Windows SharePoint Services

1.    Place the assembly for your Web Part in the bin or the global assembly cache.

If you place your assembly in the global assembly cache, your assembly must be strong named and run with full trust code permissions by default. The Web Part is available to all Web applications.

If you place your assembly in the bin, you do not have full trust code permissions when your Web Part executes. Because the permissions for the bin directory are very low by default, for this add following code into AssemblyInfo.cs file of your web part project.
[assembly: System.Security.AllowPartiallyTrustedCallers]

2.    Add the Web Part to the Safe Controls list in your web.config file, for example:
<SafeControl   Assembly="MyWebPart"   Namespace="MyWebParts"   TypeName="*"    Safe="True"/>

3.    In Design mode, select Add a web part. At the bottom of the Add Web Parts dialog box, click Advanced Web Part gallery and options.

4.    On the Add Web Parts pane, select Browse ->Import menu and then navigate to the .webpart file you created in the preceding procedure.

5.    Click Upload and your Web Part appears in the list of Uploaded Web Parts.

6.    Drag it into a Web Part zone on the page and you should see the same Web Part as on your ASP.NET page.

Published 20 July 2007 09:48 by kalpesh.prajapati
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Sharepoint link love 7-23-2007 at Virtual Generations said:

July 23, 2007 07:48
 

Carmelo Lisciotto said:

Nice instructions.

Thanks,

Carmelo Lisciotto

www.carmelolisciotto.com

August 6, 2007 19:21
 

Yehiel said:

If I have Publishing web under Publishing site, anonymous works great for father (site) and still brings auth dialog for son (web). For other templates, like Team, it works without issues.Breaking the inheritance and explicit defining of anonymous access on son site doesn't help.

January 1, 2008 13:00
 

Yehiel said:

Deactivating the lockdown mode and then create a new subsite also doesn't help

January 13, 2008 09:22
 

Raj said:

i am facing a problem like "unable to import this webpart"  Please suggest what has to be done. As i DLL is kept in GAC and registered as safe control in the web config file also.

July 8, 2008 08:56
 

Aditya said:

I created an ASP.NET website and created web parts with the web part controls provided in the Visual Studio. Everything went well till the first step. When I come to step 2, there is no DLL file created in a website.So the web part exported from the ASP.NET website does not have any DLL either.

Without DLL there is no way to deploy a web part to sharepoint site.Where am I doing it wrong?Please help.

July 8, 2008 12:53
 

Kalpesh said:

Yes. DLL is required.

Export just creates template nothin else.

July 8, 2008 13:12
 

Aditya said:

Thanks Kalpesh.So where am I doing it wrong? Or is there some other way of doing it?

July 9, 2008 06:22
 

Khilitchandra Prajapati said:

Hi Aditya,

You must have chosen the asp.net website project. This won’t give you the DLL. Rather then you should go for web application project (which is available once you install the SP1 of Visual Studio 2005). now let me tell you one easy way of creating WebParts (reusable in MOSS too, because once you develop your WebPart using namespace System.Web.UI.WebControls.WebParts - this WebPart will be used in both ASP.Net as well as MOSS, but if you chose namespace Microsoft.SharePoint.WebPartPages.Webpart then this type of WebPart can only be used in MOSS).

For more detailed explaination, take a look at http://dotnetworks2008.blogspot.com/2008/10/easy-ways-of-webpart-development-for.html

Cheers, Khilit

October 7, 2008 12:17
 

Loks said:

Very Nice

October 7, 2008 13:32
 

Confluence: SharePoint Development Wiki said:

There are various approaches to intergrating ASP.NET web application pages into SharePoint....

February 17, 2009 01:26
 

alex k bcn said:

good post, thank you. I am struggling with this at the moment, as we are building a new intranet, in which we will have to publish existing asp.Net applications.

Ill go and give it a try today!

May 6, 2009 11:30

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems