30 January 2011

The Type could not be found or is not registered as safe

Programmer's best friend is the "copy - paste".

This is the case, I was asked to create a Webpart in SharePoint, which is similar to Webpart that I developed in the past. The way I did this was: I copied (and pasted) the project, changed the Name, the Namespace, the Assembly and of course I modified the code requested.
Everything worked fine.
I moved it to my test server and then I got the following error:

A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.


This time, the programmer's best friend failed

I checked in web.config that - Webpart is defined as safe - indeed it was.
Weird ?!?!?
Again I returned to code, I checked if there is any residue of the previous Webpart code. I found that there was nothing there.
What is this? Am I rookie? It's not my first Webpart.
Then came the Enlightenment
I added to the code, ToolboxData and Guid properties, and it solved the problem.

...
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

namespace
Roi.WebParts.WebPartTest
{
    [CLSCompliant(false)]
    [Guid("9554E05E-31EF-4bcc-B0BF-0AB8CF7E5FCD")]
    [ToolboxData("<{0}:MyWebpart runat=server></{0}:MyWebpart>"),
    XmlRoot(Namespace = "Roi.WebParts.WebPartTest")]
    public class MyWebpart : WebPart
    {
...

Cheers,
Roi



25 January 2011

This page allows a limit of ... controls, and that limit has been exceeded

הפעם משהו קטן שסביר להניח שנתקלתם ואם לא תתקלו במהלך העבודה בSharePoint, במיוחד שניסיתם להוסיף Control בMasterPage.
השגיאה הנחמדה הבאה:
This page allows a limit of ... controls, and that limit has been exceeded


אני לא יודע למה מיקרוסופט מגבילים את מספר הcontrol'ים לערך נמוך
בכל מקרה, אני מגדיר את ההגדרה בWeb.Config ל500 control'ים (MaxControls="500")– זה מספיק ויותר.

כל מה שצריך לעשות, זה להכנס לשרת/ים ולתת בהגדרה MaxControls ערך גבוה  בWeb.Config.

<SharePoint>
    <SafeMode MaxControls="500" CallStack="true" DirectFileDependencies="10" otalFileDependencies="50" AllowPageLevelTrace="false">
     
<
PageParserPaths>
     
</
PageParserPaths>
   
</
SafeMode>...

נשתמע,
רועי

20 January 2011

Work with a SharePoint list and Lockdown Feature

Tip time:
When you want to prevent Anonymous Users access to forms of the list, such as Allitems.aspx, Newform.aspx, Editform.aspx and Diapform.aspx in a SharePoint anonymous web site - use the Lockdown Feature.

But how can Anonymous Users view or edit details of the list?

Two possible:
  1. Development WebPart that performs the action - sometimes worth especially in developing or buying that WebPart is generic.
  2. Create a Custom Form page with SharePoint Designer in the library that not found in the directory list. Intention to create a page in SPD in a Library such as Library Pages. The feature does not prevent the pages that are not the library related to the list itself..
The second way, Sveta and I found it in the hard way.

17 January 2011

Problems with wrong Alternate Access Mappings in SharePoint

Does it ever happen to you that you're overwhelmed with problems, and you have no idea where to start? ... That was recently the case for me.

I started a new Internet Web site in SharePoint 2007 (Anonymous site). I created a new edit site in a different port. Everything looked normal, the web parts are standards. The usual design ... All good.

Then ... Problems began to emerge:

1. One Web Part that works with the site columns, does not work well on the editing site. I looked the code, but everything looks ok... The usual site (port 80) is working properly.

2. For some reason, in the editor site, it's impossible to list using the datasheet.

3. The most serious problem, when entering into Share Point Designer, and trying to run "Detach from Page Layouts" to a page


I get "object reference not set to an instance of an object." What does this mean?


I will not give you my rigors of the journey for finding a solution, (Google didn’t help this time), but rather just give you my solution.

The most important thing once you've created a new editor’s site, change the "Alternate Access Mappings" correctly.

Notice the editing site is setup properly.

Go to the "Alternate Access Mappings" in "Central Administration"


Define the editor site to an "Extranet" with the right port (edit port).


Yours,
RoI

01 January 2011

DropDownList and div problem at Internet Exploer 6

בעידן בו יש כל כך הרבה דפדפנים, וצריך לתמוך בכולם- העבודה נעשית ארוכה יותר ולא כיפית.
כך גם במקרה הבא:
זוכרים שהיה אי פעם דפדפן IE 6, כן.. גם אני מנסה לשכוח, אבל מה לעשות צריך לתמוך בו עדין.
ישנה בעיה ידועה שDrop Down List (תג select ב Html) באקפלורר 6 תמיד עליון.

לדוגמה, אם אני רציתי ליצור תפריט ומתחתיו ישנו את אותו Drop Down זה מה שקיבלתי:



הפיתרון לבעיה זאת הוא קל. יוצרים ifram (רצויי עם source של דף ריק) באותו גודל של אותו div וifram יהיה מעל ה .Drop Down





<IFRAME id="iframeFixDiv" style="VISIBILITY:hidden; POSITION:absolute;" src="/_LAYOUTS/Test01/Blank.htm" frameBorder="0" scrolling="no">
</IFRAME>


ניקח את אותו ifram במקום כלשהו בדף, וכאשר קוראים לאותו div להופיע, מבצעים את הפונקציה הבאה בjavascript. הפונקציה מקבלת את הID של הdiv והID של הifram).


// Fix IE6 div Display before Drop Down with ifram
function FixIe6DivDisplayDropDown(divID, iframeID)
{ 
  var ieversion = 0;

  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
    ieversion = new Number(RegExp.$1);
  if (navigator.appName == "Microsoft Internet Explorer" &&
      ieversion < 7)
  {
    var myDiv = document.getElementById(
divID);
    myDiv.style.display = 'block';
    var MyIframe =
    document.getElementById(iframeID);
    MyIframe.style.visibility = 'visible';
    MyIframe.style.display = 'block';
    MyIframe.style.width = myDiv.offsetWidth;
    MyIframe.style.height = myDiv.offsetHeight;
    MyIframe.style.left = myDiv.offsetLeft;
    MyIframe.style.top = myDiv.offsetTop;
  }
}


ואז מקבלים את התוצאה הנחמדה הבאה:


נחמד.. לא?

שנה אזרחית קלילה :)