Friday, May 28, 2010

Developing/Deploying ASP.NET Web Application in SharePoint 2007 under _layouts folder

Hi Folks,

This post i will walkthrough the steps required to create and deploy asp.net web application under _layouts folder in sharepoint 2007. Also note that this application is different than the MSDN article to build asp.net 2.0 website in sharepoint 2007, since this article only works if you copy the whole project ( with .cs files ) under website folder in layouts directory which is not recommended and not a best practice.

In this article i will go through the steps to create a web application with sharepoint master page and to deploy the web application dll in GAC as well.

1) Open your VS 2008, and select ASP.NET web application template.
2) Add Microsoft.Sharepoint.dll in your project references.
3) Create a folder in your project called _layouts, the purpose of this project is to have a dummy masterpage that let you develop your custom pages with sharepoint site master page and the pages will pick the site masterpage at runtime.
4) To get a dummy application.master, get it from this link:
http://cid-4bc94054914a6469.skydrive.live.com/self.aspx/Blog%20Code/application.master

5) Right click on your project to sign your assembly of the web application, since this dll will be in GAC.

6) Open the default.aspx page that you have and update the following:



<%@ Assembly Name="<span style="font-weight:bold;">ASSEMBLYNAME</span>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<span style="font-weight:bold;">b1be248cde129fd5</span>" %>

<%@ Page Language="C#" AutoEventWireup="true"  Inherits="<span style="font-weight:bold;">NAMESPACE</span>._Default" MasterPageFile="~/_layouts/application.master" %>



<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">

    <div>

    Title of this site: <asp:Label ID="LabelTitle" runat="server" Text="Label">

    </asp:Label>

    </div>

</asp:Content>

<asp:Content ID="Content2"

ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">

Test My ASP.NET Web Application

</asp:Content>




To download the sample page, here is the link:
http://cid-4bc94054914a6469.skydrive.live.com/self.aspx/Blog%20Code/home.aspx


Note: all your pages have to have 3 content controls that mimics the contentplaceholder that you have on your custom masterpage or sharepoint out of the box master page.

Tip: to get the public key token, just drag and drop your dll in GAC and right click on your assembly in your gac folder ( c:\windows\assembly) and you will get the public key token that you need to paste on all your pages.

7) To change the master page to your pages to the sharepoint master page, write the following method on your .cs file of your page:

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);

SPWeb Web = SPContext.Current.Web;
this.MasterPageFile = Web.MasterUrl;
}



8) One you are done, publish your website using publishing feature on your web application, right click on the web application and click on publish.

set the url of the web application to be under LAYOUTS folder in sharepoint.


9) Last, Deploy the web application dll file in GAC, you can create a feature for that, for development purposes, just drag and drop the webapplication.dll in your GAC under c:\windows\assembly folder.


10) Navigate to your test page and will see it works perfect, url for example :
http://SHAREPOINTSITE/_layouts/WEBSITEFOLDER/home.aspx


Hope this helps.

Regards,
Mostafa Arafa

Thursday, May 27, 2010

Update MSDN Article: Deploying ASP.NET Web Applications in the Windows SharePoint Services 3.0 _layouts Folder

Hi Folks,

In this post, I'd like to add more updates/Tips to the posted MSDN article with title:

"Deploying ASP.NET Web Applications in the Windows SharePoint Services 3.0 _layouts Folder"
Article url: http://msdn.microsoft.com/en-us/library/cc297200.aspx

The article is going to work fine if you are building asp.net ( with limitations ) that is targeting .NET framework 2.0, if you are trying to build and follow the steps on an ASP.NET application that is targeting .NET Framework 3.0 or 3.5 ( specially if your application has AJAX and Silverlight modules on it) then here is the changes/Tips that you might tackle and change:

1) The article doesn't tell you how to have a page that's rendered correctly in your VS.NET while development, the trick on this, do the following:
a) create a folder in your asp.net application called _layouts, and copy the application.master file from LAYOUTS folder and paste it on _layouts folder.
b) Now the page will render correctly in VS.NET.
c) You won't be able to build your website since the application.master has a lot of usercontrols and components that doesn't exist in your application.
d) to fix this, simply remove all usercontrols that you have in the application.master and you then be able to compile and build your website.
e) we added application.master just because to have our pages render correctly in our VS.NET IDE and to enrich the design experience of our pages and user controls.
d) As a best practices, no need to hard code the master page name in your code, simply replace the code in the OnPreInit event to the following:

// Old code in the article:
SPWeb Web = SPContext.Current.Web;
string strUrl = Web.ServerRelativeUrl+"/catalogs/masterpage/GamePoint_ThemeBlueDefault.master";
this.MasterPageFile = strUrl;

// New code:
SPWeb Web = SPContext.Current.Web;
this.MasterPageFile = Web.MasterUrl;

The above code will assign the the site masterpage to the custom page. and no need to specify the name of the master page, and this add a major flexibility to your solution specially if you provide your client with different custom master page in your sharepoint site ( as in my case ).

2) The article is telling you just to comment the authentication section in the web.config, this is not true 100%, what you suppose to do is to remove any attribute that exist on the web.config of the sharepoint site otherwise you will get duplicate entry error. To fix this:

a) remove any duplicate entries on your web.config file from your asp.net application.

b) no need to have web.config in your site if you don't have any custom entries on your site. and in this case, your site will run under the configuration of the sharepoint site that exists in sharepoint site folder.


With these 2 tips you will be able to build any asp.net 2.0/3.0/3.5 application with no limitations and make use of the full functionality of VS.NET Design tools.

Hope this helps.



Regards,
Mostafa arafa

Tuesday, May 25, 2010

SharePoint 2010 Master pages, Js, CSS tips

Hi All,

I want to share some ideas and tips on masterpage changes in regard of using Master pages, css and ribbons in Sharepoint 2010:

1) In sharepoint 2007, when you develop custom pages under _layouts folder, those pages doesn't take the site master page, you have to configure them in your solution to reference a customized master page. while in Sharepoint 2010 one of the good enhancements is that the site master page is applied on your custom pages under layouts folder. Good Feature to know.

2) To set the master page in your custom pages in SharePoint 2010 use the following lines of code:

web.MasterUrl="/_catalogs/masterpage/minimal.master";
web.CustomMasterUrl="/_catalogs/masterpage/minimal.master";


This allow your pages to get the custom master page for the site, and if the referenced master page doesn't exists, the site will default to the default master page and then the site won't break.

IMMPORTANT Tip: by default MasterUrl and CustomMasterUrl set to "_catalogs/masterpage/default.master" and to change the default to have to set BOTH properties to your new master page.

3) You can start your custom master pages with minimal.master that you can download or use from sharepoint 2010.

4) V4.Master is a new master page in sharepoint 2010 and the default sharepoint 2010 master page user interface with Ribbon support.

5) Sharepoint 2010 javascript files has been enhanced, Microsoft split the js files into smaller minified files to be used on-demand only.

6) Sharepoint 2010 css files has been enhanced, Microsoft split the css files into smaller files that will be downloaded on-demand by any page.

7) To debug js files in Sharepoint 2010, what you need to do is modifying the web.config and adding the following attribute under system.web:



8) To add declaratively/dynamically (no code behind) the master page reference in your custom page based on the site selected master page:

~masterurl/application.master

9) As a best practice, it is recommended not to have more than 4-7 tabs in your Ribbon.

10) Ribbon doesn't support tables, all look and feel managed through css files, and the main css for the ribbon is called corev4.css


Hope this insights help.


-- Reference:
a) MSDN:
http://msdn.microsoft.com/en-us/library/dd776256(v=office.12).aspx

b) Professional SharePoint 2010 Development - Wrox

Regards,
Mostafa arafa

Monday, May 24, 2010

NOVA Code Camp 12 June - MS Reston Office

Hello Everyone!

We have an impressive lineup of sessions you can see below. We have not yet made up a schedule, but we just wanted to let all of you know which of your talks were selected with plenty of time to prepare. We expect to have the schedule firmed-up by next weekend. We have some important details to share with you.

Location
The Code Camp is on Saturday June 12th from 8:30am to 5:45pm at the Microsoft Office Facilities.

The address is:
12012 Sunset Hills Road, Reston, VA 20190

Ask the Experts
During lunch, we are running an Ask the Experts where you’re the experts! We will be grouping the speakers into four groups based upon session topic. Each group will then be able to entertain questions from attendees.

Speaker Dinner
We are holding a post-code camp dinner at Clyde’s in Reston. It’s within easy walking distance from the code camp. Please let me know if you will be attending so we can make reservations.

Speaker Selections
Please note if you received this e-mail, then at least one of your talks was selected. If you do not see your name on the list below, then please let me know.

Chagoury, Antonio Building an iPhone web app for your DotNetNuke module
Ames, Ned If Software Modules Were People
Blumenauer, John Building Extensible Silverlight Apps with MEF
Busse, Chris Promotion & Privacy (or lack thereof): Working with the new Facebook APIs
Cochran, Joel An Introduction to Expression Blend
del Mundo, Paolo Writing your first Windows 7 Phone App
Elzoghbi, Mostafa SharePoint 2010 Development
Griffin, Kevin jQuery From The Ground Up
Hazzard, Kevin Better Contracts. Better Code.
Hoerster, David Introduction to WCF Data Services and OData
Lele, Vishwas Architecting for Azure
Makogon, David Azure: The Essential Setup Guide
Michelotti, Steve ASP.NET MVC 2
Miller, John Building Facebook Apps with Windows Azure
Nguyen, Tuan Intro to BDD and SpecFlow
Rushdan, Habeeb Intro to Object Oriented Programming in .NET via C#
Schoolcraft, Jeff Rails FTW
Sizemore, John Source Control You Won't Hate: SVN and Git
Snowman, Geoff The Service Bus in the Sky - How to Connect Applications across Firewall Boundaries Using Windows Azure AppFabric
Van Lowe, Van Building Silverlight 4 Business Application Using WFC RIA Services


Thanks and we’ll be seeing you in just a short few weeks at NoVa Code Camp!

Sign up : http://novacodecamp.org/

Latest updates: follow @novacodecamp or hashtag: #NOVACC

See you then !

Regards,
Mostafa arafa

Tuesday, May 18, 2010

Access denied by business data connectivity

Hi,

I was trying to create an external list in sharepoint 2010 and i was getting this error: "Access Denied by Business Data Connectivity" when i am trying to view the external list in my sharepoint 2010 site.

The fix for this problem is easy since the cause of this error is : The business data connectivity service is not configured in sharepoint- permissions are not set !

What we will do is to configure the BDC service by set the security permissions on it:

1) open central administrations.
2) select application management.
3) select business data connectivity service.
4) Hover on your application and select set permission from the menu.
5) Add users that will have the permissions to use this BDC Application and assign the required permissions.
6) Click Ok.

Refresh the external list and will works :)

Hope this helps.

Ref.:
http://blogs.msdn.com/bcs/archive/2010/01/28/bcs-team-channel-creating-an-external-content-type-in-sharepoint-designer-2010.aspx


Regards,
Mostafa arafa

Monday, May 17, 2010

No confusion for SharePoint Project Templates in VS 2010

Hi Folks,

VS 2010 has shipped with wide variety of project types for asp.net/sharepoint developers, in this post i will clarify the use for the most common project types and items used for building sharepoint 2010 solutions:

1) Import Sharepoint solution package: this project template allows you to import existing wsp files that you developed before.

2) Import Reusable workflows: this template allows you to extend created/developed workflows using SPD in VS 2010. VS 2010 workflows provide more capabilities that doesn't exist in the SPD workflow designer. Once you are done, you can also deploy using VS 2010.

Note: once you modify the imported workflows from SPD you wont be able to open it back using SPD.


3) State Machine workflow: in this template you can create state machine workflows using VS 2010.


4) Application page: Use this page to add any asp.net pages in sharepoint sites.


5) User Control: this is a regular ascx user control that you can drag-drop it on your application pages.

6) Web part: this is a normal webpart that we use to develop since MOSS 2007.

7) Visual Web part: This is a visual webpart that you dont need to render it is interface, it contains a webpart and a usercontrol item.

Happy sharepointing.....


Regards,
Mostafa arafa

SSO in SharePoint 2010

Hi Folks,

Single Sign On (SSO) one of the most important feature to connect to external systems from SharePoint, In SharePoint 2007 You have to configure SSO service and set the required username/password to connect to external systems.

In SharePoint 2010 the new name for SSO is SSS: Secure Store Service.

Here is some general consideration about SSS in SharePoint 2010:
1) SSS is a service in SharePoint 2010 that runs on the application server.
2) SSS provides a DB that store credentials for ApplicationIDs.
3) Application ID : is your token to access the external application, the token might represents one/group of users.
4) It is recommended to run SSS on separate application pool and on separate application server.
5) Use different SQL Server to store SSS credentials information.
6) You create SS Target Application Types:
a) Group: map group of people to access this external app.
b) Individual: map individuals to access this external app.

This is a general post about SSO - SSS, following posts will explain more....


Regards,
Mostafa arafa

Thursday, May 13, 2010

Error connecting to a sharepoint list in PPS Designer

Hi All,

I was trying to connect to a sharepoint list in PPS designer 2010 and SharePoint 2010 and i'm getting this error:










I checked the eventlog and i found the following error:

The following data source cannot be used because PerformancePoint Services is not configured correctly.

Data source location: http://PORTAL/BI/Data Connections for PerformancePoint/1_.000
Data source name: New Data Source

The PerformancePoint Services Unattended Service Account is not set. The setting is located in "Manage service applications" in SharePoint Central Administration under the PerformancePoint Services management page.

I opened the central administration - > Application management and select manage service applications.

Select performance point services application and click on pps application settings link and try to set the secure store service (sss). set username and password and hit ok.

You might get this error message:

The Microsoft Secure Store Service application Secure Store Service failed to retrieve the master secret key. The error returned was: 'Unable to obtain master key.'. For more information, see the Microsoft SharePoint Products and Technologies Software Development Kit (SDK).

To fix it, go to the manage service applications and select secure store service and click on generate new key and ok.


Go back to the PPS and set the username/password PPS service account.

Hope this helps, happy sharepointing 2010 !!!



Regards,
Mostafa arafa

Wednesday, May 12, 2010

Can't see Site collection features in SharePoint 2010

Hi All,

If you are trying to find out "site collection features" link in the site setting page in sharepoint 2010 and you couldn't find out the site administration section at all this is because the logged in user doesn't have a permission as a site collection administrator, open central administration site:

1) Select application management tab.
2) Click on change site collection administrators link under site collection tab.
3) add your self as site collection administrator.
4) refresh the site settings page and you will see all site collection administration section.

Hope this helps.

Regards,
Mostafa arafa

Tuesday, May 11, 2010

File Not Found in SharePoint 2007

Hi All,

"File Not Found" is one of the most confusing errors that can be caused by a lot of reasons, In my case i have the site is up and running except my custom SharePoint 2007 pages under layout folder.

I developed a custom page which uses WCF REST API classes, and it is working fine on my development VM and once i moved wsp to the staging vm i was getting "File Not Found" and after turn off the customerrors and enable stacktrace in web.config, still i didn't get any details more than the method name that raises the error !!

After spending almost 2 hrs to figure out why some pages in my solution (wsp) is working and other they are not, I found that the pages that throw an error are using
Microsoft.Http.dll and Microsoft.Http.Extensions.dll that doesn't exist on the staging vm. and i remembered that those dlls are registered after you installed WCF REST started Kit.

The problem was missing an assembly and not a file !!!

To deploy those assemblies:
1) WCF assebmlies you can find them on the following path:

C:\Program Files\Microsoft WCF REST\WCF REST Starter Kit Preview 2\Assemblies

2)Copy both dlls:
Microsoft.Http.dll and Microsoft.Http.Extensions.dll

3) Add them to your wsp under GAC folder or drag and drop them to GAC.

Hope this helps.

Resources:
1) WCF REST API :
http://msdn.microsoft.com/en-us/netframework/dd729270.aspx


Regards,
Mostafa arafa

Monday, May 03, 2010

How to enable Session State in SharePoint 2010

Hi Folks,

If you are trying to use any of SharePoint 2010 Features that use Session state service in SharePoint, Then you need to enable session state service in SharePoint 2010 since it is disabled by default, Here is how to do it:

1) Open SharePoint 2010 Management Shell (As Administrator) and type the following command:

enable-SPSessionStateService

The shell will prompt you to enter the required DB name to store the session state data, type the database name.

Once you get the prompt back to you, You can check the created DB name, under sharepoint instance: SERVERNAME\SHAREPOINT to make sure the DB has been created.


2) Open the site web.config file and enable the session state on the site:

enableSessionState="true"

3) Reset IIS.

Check the feature or navigate to the site template that depends on session state ( For Example: Project Database site template) and will see it is working.

Hope it helps.

Regards,
Mostafa Elzoghbi

Learn C# 4.0 By example and walkthrough

Hi All,

I'm writing this post to share with C# Developers and folks how to get to know C# New/Enhanced Features by examples by going through a well-prepared learning tutorials to start applying the new features by example:

1) C# 4.0 Code samples:
http://code.msdn.microsoft.com/cs2010samples

2) C# 4.0 walkthroughts:
http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx

I will post more examples in this blog about different usages/applications for the new C# 4.0 features that we were working on it with the product team.


Regards,
Mostafa arafa