Sharepoint WebPart not installing - sharepoint

What tips do you have for debugging a WebPart that is not installing? One tip per response.

One of the most common problems for newbies is probably code access security. A great article for troubleshooting this is Common Security Pitfalls for Web Part Developers by Jan Tielens. It was written for SharePoint 2003 / WSS 2.0 but the same principles apply in SharePoint 2007 / WSS 3.0.
The error is usually something like "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe."

One Quick Solution I can think of seeing your Error message is that,you somewhere in the code have a <%%>. You can try wrapping that part with
<div id="temp" runat="server"> var x= '<% = x.ClientID %>' </div>

Sharepoint does not allow Inline scripting for any content except that in the _layouts folder out of the box. You need to move your inline code block to the code behind.

Put a breakpoint in the constructor and debug it. You probably don't want to do anything in the constructor. I think we may have been doing a RunWithElevatedPrivileges there and that was a problem when adding a web part to a page, but not using the web part if it was already on a page.

I am using webparts in sharepoint and I didn't find a way for debugging. I just copy the code into another application to debug it

Related

Developing ASP.Net User Control to be imported to SharePoint MOSS 2007

Apologies if this has been answered, but I could not find a similar question:
I am developing a webpart for MOSS 2007. I am using WSPBuilder to built a visual webpart (ascx) and everything works fine, but the development/debug cycle is just painfully slow, so I'd like to know if it is possible (without being too painful) to develop the user control faster using an .Net Web Application project with all of the nice F5 debugging, then import the final product into my SharePoint visual webpart.
The user control interacts with a LOB system (SQL) and does not reference the SharePoint API at all. (The reason I am building this as a webpart is because I don't need another web app to run this one page, so putting it into a webpart on a new webpart page on my existing site is the best solution IMO.) I would obviously need to import (reference?) my data access classes into my "temp" web app, but think that would not be too much trouble.
I realize this will be extra effort to get this set up, but am thinking the payoff will be reduced development time of the actual user control using a little web application vs having to use the compile/build WSP/deploy WSP/reset ISS/test/make a change/repeat cycle that MOSS requires. (I guess SP2010/VS2010 has spoiled me with the native SharePoint tools available.)
Update:
I have successfully built a simple web app with one page and loaded up my UC on the page. (I had to comment out all of the Sharepoint Import and register statements that WSP Builder added to the UC for me when I created the webpart.) I added references to my utility classes (which I left in the obj\Debug folder in the original SharePoint project). It took me a while tinkering with everything to get it to work, but the steps ended up being pretty simple and I think I can replicate the steps quickly for future projects. Once it was set up, I was able to rapidly design the UC and build in the UC functionality using the typical F5 debug cycle. Unless someone can show me why this is not a good idea, I plan to repeat this for future projects! Thanks to everyone for thier input.
.
Update 2
Well, I am not sure what I did but moving the UC back into SharePoint proved to be troublesome. The first time I did it, I spent several hours getting it to work in SharePoint, making me question whether it was worth it. However, I am stubborn and tried it again. This time, I only copied and pasted the markup below the "header section" (the part with all of the <%# . . . %> statements) in the ascx file and everything went perfectly. I think I must have changed something inadvertantly the first time. I think I will continue this pattern as it is so much faster to build and test the UC in an ASP.NET web app. (Again, this only works if you are not referencing the Sharepoint API anywhere in the UC.)
The answer here is the SmartPart. It is perfect for just the scenario you are describing. Very easy to create a Usercontrol using "vanilla" ASP.NET and have it work as a webpart in SharePoint. I've outlined the steps to migrate from ASP.NET webpage to statically bound SmartPart on my blog.
What you intend to achieve is surely a nice idea.
Just remember to strong name your user control, drop it in your Server's GAC, update SafeControls section of your SharePoint 80's web.config.
All these setps are one off, after each successive builds (of your web control), you have to just deploy the control (used forcede deploy) in GAC and reset IIS.
You can add this control to toolbox in VS by selecting 'Choose Items' and selecting ther assembly you just deployed.
In addition you can create a test ASP.NET page to test the functionality of your control.

Porting an aspx website to sharepoint?

We have a requirement from a client for porting an ASPX website to sharepoint :
Though the site is being served in ASPX there are no form submissions so effectively, they are just static pages without any server side processing required.
However, there is a common header and footer being used.
Here are some of the features being used in the existing site :
sifr for font substitution (using non standard web fonts)
flash animations
javascript and some jquery
common header and footer for all pages
My question is how feasible is it to port this website to sharepoint ?
Can i use sifr (or flash for that instance) in sharepoint ? or do i have to port it to silverlight ?
What is the general procedure for converting web applications to sharepoint ? Also i came across this http://www.metalogix.net/Products/Website-Migration-Manager-for-SharePoint/ for migration of website to sharepoint.
Can javascript be used in sharepoint ?
How can i have common header and footer in sharepoint documents ?
Pardon my ignorance or any discrepancies in any of my knowledge since i havent worked with any microsoft technologies i would really appreciate some relevant answers from the community here.
Thanks.
Yes, you can use flash, javascript and jquery in sharepoint. Keep in mind that sharepoint is built over asp.net.
I never used sifr, but if it is just flash there shouldn't be any problem using it with sharepoint. Anyway, you can start considering using webfonts instead.
Common header an footer pages are also easy to implement with sharepoint as you can use the master pages, wich are exactly for that.
We did something quite similar to that and what we did was place the pages under Layouts and attach them to the master page. This is about 20 mins of work, but it looks like SharePoint. We needed that to integrate an LOB system to become a part of a large MOSS portal

ASP.net site sharepoint integration

I have created a test website that contains a single ASP.net index.aspx file that contains a gridview listing information from a MSSQL database.
I would like to have this made available as a webpart on our sharepoint intranet, how would I go about doing that?
You can just put your page under Template/Layouts and attach it to some SharePoint master page. It will look and feel like a regular SharePoint page.
Of course, that is good if you're into the quick&dirty approach :)
You will need to create a web part from the page you already have.
I would suggest isolating your gridview in a user control (ascx) instead of directly on the aspx page, it will be easier to use it in a web part that way.
To create a web part, you should probably start by downloading WSPBuilder or a similar tool that will do most of the work for you.
The following tutorial will give you the information you need on how to create a web part from a user control.
You should have no problem linking to your database or anything else. A web part behaves just like a user control.

can not add webpart to sharepoint page

i create a website on my local machine but i can't add webpart to web page, it don't rise any error but th webpart don't display to the page. anyone help me.
Thanks
I know this is an old question, but it's ranking high in Google results, so I figured I'd answer it anyway.
Make sure you're not running any code in the layout page's codebehind that calls and then closes SPContext.Current.Web. I had this exact behavior and that was the culprit
To test, add a different web part to a default page layout. If it adds, then it's either your web part or your code behind. If you can't add any web parts to your custom layout, it's your code behind. If it's just your web part, it's your web part.
Remember, SPContext.Current.Web returns a reference to the current SPWeb object. SharePoint will close the object itself when it's done, and closing it early can cause "unpredictable behavior."
We had the same problem with Firefox some time ago, but the problem disappeared when we installed SP2 for SharePoint 2007. The only thing that surprises me is that you also have the problem with IE.

SharePoint ASP.NET Mock Site

Does any one know if there is a ASP.NET website available that is a pretty good clone of the style and layout of a SharePoint site? I don't need the functionality of SharePoint, I would like to be able to quickly mock up some controls for SharePoint, with out having to actually deploy stuff to the server, and want to be able to see what the controls would look like rendered in SharePoint.
Make sense?
If there is nothing available I'm just going to do a "save complete" with FireFox on my SharePoint site, and convert the results into a master page that I can use. If someone else has already done the work, that would be fantastic.
Heather Solomon has an excellent SharePoint CSS Cheat Sheet. Also, if you use sharepoint native controls like the SPGridView, most of the styling will be inherited / already implemented for you.
Your 'Save Complete' idea is the one I would suggest. You could also have some sort of bookmarklet/script that receives a html page url and injects it into the sharepoint page without actually changing it, but it is way more complicated.
My advice would be to use SharePoint Designer to play with the design and to use Features for deploying the customizations. Your question is pretty vague in that I can't tell if you have access to a VM to do a test install? Also, are we talking WSS 3.0 or MOSS 2007 or the latest version? Is it a publishing site? What kind of controls are you working on? Web Parts?

Resources