Error : Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

Hello All

I have created list in my SharePoint Site. And my requirement is to get data from SharePoint Site.

Here is my Simple code:

using (SPSite site = new SPSite(siteurl))
{
using (SPWeb web = site.OpenWeb())
{
SPList lstUsers = web.Lists["SiteUsers"];
SPQuery Qry = new SPQuery();
Qry.Query = "<Where><Eq><FieldRef Name='IsActive' /><Value Type='Boolean'>0</Value></Eq></Where>";
DataTable dtUsers = lstUsers.GetItems(Qry).GetDataTable();
if (dtUsers != null && dtUsers.Rows.Count > 0)
{
//Bind the data
}
}
}
}


When I am trying to get data from the SharePoint List, I got this Error Message:

Error : ‘Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack’

After doing some research I found solution. I need to change the Authentication mode in configuration file from ‘Form’ to ‘Windows’.

Solution : <authentication mode="Forms"> replace with <authentication mode="Windows">

That’s it, Problem Solved.
It works fine for me, Hope it helps

Forms Authentication in SharePoint

Hello All,


Here is the good article which explain how to extend FBA site from Window Authenticate site and How to configure Forms Authentication in SharePoint Site.

This article provides detailed description of how to configure Forms Authentication with SharePoint site with code.

Thanks.

Creating Custom Site Definition in WSS / MOSS

Site Definition: It is foundation on which all sites and templates are built. Inside each site definition sub directory the aspx pages for the various WebPages and lists that make up site definition are stored.

The Site Definition folder is located at ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates’ on the SharePoint Server.
Each Site Definition has its own sub directory under this folder.

Steps to Create Custom Site Definition:

1. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates’

2. Copy the STS directory and paste it to back in same directory, Rename the Copy STS directory to DEMOTEST.

3. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033’

4. Follow the same procedures as you follow in step -2 and step-3 for STS directory.

5. Navigate to ‘C:\Program Files\Common Files\Microsoft Shared\web server
extensions\12\TEMPLATE\1033\XML’

6. Copy the WEBTEMP.XML file and paste it in to same directory and rename it ‘DEMOTESTWEBTEMP.XML’.

7. Put the following lines into the DEMOTESTWEBTEMP.XML

<?xml version="1.0" encoding="utf-8" ?>
<!-- _lcid="1033" _version="12.0.4017" _dal="1" -->
<!-- _LocalBinding -->

<Templates xmlns:ows="Microsoft SharePoint">

<Template Name="DEMOTEST" ID="10001">

<Configuration ID="0" Title="Sample Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a site for teams to create, organize, and share information quickly and easily. It includes a Document Library, and basic lists such as Announcements, Calendar, Contacts, and Quick Links." DisplayCategory="Custom Site Definitions" > </Configuration>

<Configuration ID="1" Title="Sample Blank Site" Hidden="FALSE" ImageUrl="/_layouts/images/stsprev.png" Description="This sample template creates a Windows SharePoint Services-enabled Web site with a blank home page. You can use a Windows SharePoint Services-compatible Web page editor to add interactive lists or any other Windows SharePoint Services features." DisplayCategory="Custom Site Definitions" > </Configuration>

<Configuration ID="2" Title="Sample Document Workspace" Hidden="FALSE" ImageUrl="/_layouts/images/dwsprev.png" Description="This sample template creates a site for colleagues to work together on documents. It provides a document library for storing the primary document and supporting files, a Task list for assigning to-do items, and a Links list for resources related to the document." DisplayCategory="Custom Site Definitions" > </Configuration>

</Template>

</Templates>

8. Reset IIS

9. Go to SharePoint Central AdministratoràCreate Site Collection. In TemplateSelection
Section, the new tab named ‘Custom Site Definitions’ available.

That’s it...Hope this helps

Adding users to SharePoint Programmatically

Hi All

The code snippet shows you how to add users to SharePoint Programmatically. This code looks for a User who registers with FBA site and Pull them in to SharePoint Group.

[C# code snippet]
MembershipCreateStatus status;
If (Membership.GetUser("UserName") == null)
{
//Insert into MemberShip's Database
Membership.CreateUser("UserName", "Password", "Email", "Not used", "Not used", true, out status);
If (status.ToString().ToLower().Equals("success"))
{
MembershipUser User=Membership.GetUser ("UserName");
Using (SPSite site = new SPSite ("http://sharepoint site url"))
{
Using (SPWeb web = site.OpenWeb())
{
string _usernameWithProvider = String.Format("{0}:{1}", System.Web.Security.Membership.Provider.Name, User.UserName);
web.AllowUnsafeUpdates = true;
SPGroup grp = GetGroup ("Visitor", web); //Visitor is group available with you SharePoint site.
if (grp!= null)
{
web.SiteUsers.Add(_usernameWithProvider, User.Email, User.UserName, "");
web.Groups [group].AddUser(_usernameWithProvider, User.Email, User.UserName, "");

}
}
}
} }

private SPGroup GetGroup(string groupName, SPWeb web)
{
SPGroup spReturn = null;
try
{
spReturn = web.Groups[groupName];
}
catch (Exception ex)
{
return spReturn;
}
return spReturn; }

Hopefully This helps...

AJAX UpdatePanel and SharePoint

Hello Guys,

A Days before i had added ajax update panel in my usercontrol,the usercontrol is render in webpart with sharepoint application.but i can't see the affect of update panel on my sharepoint site,and i got frushtrated.finally i was going for some R&D and got solution.

Basically, the workaround is adding an additional function to your code page that alters the _spFormOnSubmitWrapper and the _spFormOnSumitWrapper So, You need to add following line of code in your Page_Load event and it works for you.

[C# Example]
if (this.Page.Form != null)
{
string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
if (formOnSubmitAtt == “return _spFormOnSubmitWrapper);”)
{
this.Page.Form.Attributes["onsubmit"] = “_spFormOnSubmitWrapper();”;
}
}

ScriptManager.RegisterStartupScript(this, typeof(CompanyRegistration),“UpdatePanelFixup”,“_spOriginalFormAction=document.forms].action;_spSuppressFormOnSubmitWrapper=true;”,true);

That's it...Problem Solved,Hope it works for you.

Error : Code blocks are not allowed in this file

Hi All

I also faced such error in one of SharePoint site when I add one .aspx page, which contains some inline script and code. But at last I found solution for this error. When you add inline script or code in you .aspx page, it works fine as long as the page remain uncustomized in ghosted state. But as soon as you modify any aspect of this page with the SharePoint designer, it turns into unghosted state, WSS then begin to use safe mode to process it. So you just need to add following line of code within the SharePoint section of the web.config file.

<SharePoint>
<SafeMode…>
<PageParserPaths>
<PageParserPath VirtualPath=”Your Page Path” IncludeSubFolder=”true” CompilationMode=”Always” AllowServerSideScript=”true” />
</PageParserPath>
</SafeMode>
</SharePoint>

This Error is very common when you are going add site pages within SharePoint site and make some modification in page with SharePoint Designer.

Hope it will work for you guys. It seems work fine for me.

How to get distinct value from sharepoint list

Hi All,

Here is code which get distinct value from sharepoint list after using CAML Query.

public static DataTable GetShipType()
{
SPWeb web = SPContext.Current.Web
SPQuery qry = new SPQuery();
qry.Query = "";
DataTable dt = lstFloorPlan.GetItems(qry).GetDataTable();
DataView v = new DataView(tbl); return v.ToTable(true, "Type");
}


That's it.You'r done.
Samip.