Creating a SharePoint Application Page for Anonymous Access

November 28, 2011 Leave a comment

From time to time, you may need to create a few SharePoint application pages for anonymous users. Like log on page, the page to recover or reset passwords, a page to guide through the registration processes, etc. Besides to set up you SharePoint site to allow anonymous access, the key here is that you cannot use the default LayoutsPageBase base class for your page because it would trigger SharePoint to prompt anonymous users to log on.

Instead, you need to use another base class for your anonymous application page called UnsecuredLayoutsPageBase. You can find its MSDN reference at:

Your page class would look like this:

public partial class ApplicationPage1 : UnsecuredLayoutsPageBase
     protected void Page_Load (object sender, EventArgs

Exploring LINQ to SharePoint 2010

June 2, 2011 1 comment

One of the most important new features in SharePoint 2010 is LINQ to SharePoint And which has made the CAML query is deprecated style because finally LINQ to SharePoint translated to CAML Query then SQL commands.

Here are some steps you have to do to get the benefit of the LINQ intellisence SharePoint provides while using SharePoint LINQ.

Launch a cmd-window and navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\bin

Run the following command to utilize the SPMetal.exe tool with the following syntax:

SPMetal.exe /web:http://yoursite /code:C:\YourEntityFile.cs


Now navigate to C:\ (or wherever you chose to output your file) and make sure the file has been generated:

Open up the file and take a look at the content that SPMetal now have provided us with:

Note that the class name is now MyEntitiesDataContext. It’s based on the name you specify as your code file in the SPMetal.exe command line tool.

If you were to use /code:C:\GlobeSoft.cs instead, it would generate a class called GlobeSoftDataContext.

  1. Create a new project (I’m going to create a new Visual Web Part project)
  2. Import your DataContext-file by choosing your Project -> Add -> Existing Item:
  3. Specify your file (mine is called MyEntities.cs):
  4. Make sure it’s properly placed in your project structure – then we’re good to go:
  5. Add The proper references

Now in order to use LINQ to SharePoint, you also need to reference the Microsoft.SharePoint.Linq  assembly. Point to references, right-click and choose “Add Reference” and select the Microsoft.SharePoint.Linq.dll file:

In your code, reference the assemblies:

What you should’ve done up until now is this:

  1. Generate your entities using the SPMetal.exe tool
  2. Reference the newly created file from your SharePoint project
  3. Make sure you’re using the proper references for System.Linq and Microsoft.SharePoint.Linq
  4. Be ready to code 🙂


In my example I will have a Visual Web Part that will use LINQ to SharePoint to fetch all Announcements from my Announcement-list and work with those results. If you want to see the entire project, look at the bottom of this article where you can download it.

IntelliSense! ……… 🙂

While you code your queries using LINQ to SharePoint, you will now have access to IntelliSense, which you did not have with CAML queries:

very easy to get started with LINQ to SharePoint, just use SPMetal tool to generate your entity classes and then open  Visual Studio to start coding.

Thanks …. And hope it was helpful

Have fun with LINQ to SharePoint

Categories: Development