Wednesday, July 25, 2012

How to create page layout in SharePoint 2010 using visual studio 2010



We know that we can create page layout using SharePoint Designer but how to create page layout using visual studio 2010.


here am trying to show how to create page layout using visual studio in SharePoint 2010.


Here am taking article page as parent page. For this need to activate two features 


a) SharePoint Server Publishing Infrastructure.(This feature available in  Site collection features which is under site collection administration)
b) SharePoint Server Publishing.(This feature is available in Manage site features which is under Site Actions)


if these two features are not activated then we wont see article page content type in Content Types. see the image.


activate these two features






1) Open visual studio --> File--> New --> Project.


2) Select SharePoint 2010 in left panel, then select Content Type template in the middle panel and then specify project name.


3) Specify URL location for debugging and deploying this solution as sandbox solution for testing purpose only.


4) Choose Content Type from the drop down here am selecting 'Article Page' and Click on Next.


5) Now it will automatically open Elements.xml file of ContentType1. Now modifying Name of the Content Type and save the file. 


6) Now Add Module for actual pagelayout name it as PageLayoutModule






By default module has two files one is Elements.xml and sample.txt


7) Now delete sample.txt file from PageLayoutModule




8) Now adding pagelayout page i.e UdayPageLayout.aspx to PageLayoutModule.




9) Design pagelayout. Here am adding one table in that am adding three webpart zones.


These webpart zones are used to place webpart.


here the code which i was used.



<%@ Page Language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>


<%@ Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:content contentplaceholderid="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server" />
</asp:content>
<asp:content contentplaceholderid="PlaceHolderMain" runat="server">
<table cellspacing="0" border="0" width="100%" cellpadding="0>  
  <tr>
       <td width="100%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Top" Title="loc:Top" />
       </td>
       </tr>
       <tr>
       <td>
       <table width="100%">
       <tr>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" Title="loc:left" />
       </td>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Right" Title="loc:right" />
       </td>
       </tr>
       </table>
       </td>
       </tr>
       </table>
</asp:content>





10) Now open Elements.xml which is under PageLayoutModule and it looks like this.


                                     
11) Now change File tag's URL attribute because inorder to display your custom pagelayout in pagelayouts(which is in ribbon while the page in edit mode).



12) Now am adding properties to page layout. in this we specify Title of the page layout and ContentType i.e pagelayout content type and PublishingAssociatedContentType i.e name of the parent content type and Content Type ID of the Elements.xml which is under ContentType1.


And also Add URL attribute in Module tag.






13) Now open Features-->Feature1, ContentType1 and PageLayoutModule are in Items in the Solution.


Move these two items to Items in the Feature.


15) Now deployee the solution.


After successfully solution deploye. The page layout is available at http://<<server>>:<<port>>/_Catalogs/masterpage (_Catalogs/masterpage) is specified in pagelayoutmodule.
To go that page follow these steps


16) Now open your site --> site actions -->site settings, Click on Master pages and layouts which is uder Galleries.


17) Now you can find newly deployed pagelayout file in the list of files and its status as "Draft".


18) Now checkin the newly added pagelayout file. we can do it in two ways. one is through ribbon and through item menu.


19) While checkin select major version and add your comments and click on "OK".


20) Now the pagelayout status changes to pending it means we need to approve it.


Select the pagelayout and click on "Approve/Reject" from ribbon.


21) Then select "Approved" radio button in Approval Status. Click on "OK".


22) Now the pagelayout file status is approved, so that pagelayout is available.


23) Now Go to Site Actions --> More Options.


24) Select Page in left panel and click on Publishing page.Now click on Create.




25) Now you can see newly added pagelayout as (Name of the content type which is in Elements.xml file under layout1) Title value in Elements.xml which is under PageLayoutModule.i.e (CustomePagelayoutSample) Custome Page Layout.




now click on Create.


26) Now you can aslo see the newly added content page layout in page layouts(which is in ribbon).


Now you can add your webparts in webpart zones. And CheckIn Then Publish the page.


Here the Solution Code File.
Thats it.....


Thanks...

Tuesday, July 24, 2012

Trick and Tip: How to hide view all site content from anonymous users in SharePoint 2010


with the reference of MySharePointworld

1. Go to "Site Actions" ==> "Site Settings"
2. Under Galleries, click on "Master Pages"
3.Select default.master and select "Edit in Microsoft Office SharePoint Designer".
4. In "Design" view locate "View All Site Content" on the left-hand-site navigation bar and click on it.
5. Go to "Code" view. You will see the following code highlighted:
<Sharepoint:SPSecurityTrimmedControl runat="server" PermissionsString="ViewFormPages">
 <div>
<SharePoint:SPLinkButton id="idNavLinkViewAll" runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" Text="<%$Resources:wss,quiklnch_allcontent%>" AccessKey="<%$Resources:wss,quiklnch_allcontent_AK%>"/>
 </div>
</SharePoint:SPSecurityTrimmedControl>
Change the PermissionString attribute value of the Sharepoint:SPSecurityTrimmedControl XML element from ViewFormPages to BrowseDirectories.
Save the default.master. If you login as an anonymous user you will not see the "View All Site Content" link. However when authenticated you will see this option.

NOTE:
The "BrowseDirectories" permission is common to both the "Members" and "Owners" group permission levels, but is not set for the "Limited Access" (anonymous users) permission level. 
If you want to block it for all users, use "FullMask" instead of "Browse Directories".

Trick and Tip: Change Top toolbar display in Firefox


From Heather Solomon’s site


If you are working with SharePoint in Firefox, the top toolbar (Welcome menu, My Site, My Links) may not display correctly. Click here for a screenshot.
Add this to your CSS to correct this problem:
.ms-globallinks {
    white-space:nowrap
}
This works in Firefox and won't wreck IE. 

How long "!New" image stay with newly added file




The default is 2 days (or 1 full day plus time until midnight the next day)
To change the value (you must have admin access to the server):
  stsadm -o setproperty -pn days-to-show-new-icon -pv Number_Of_Days -url http://Your_Server_Address
To check your current value:
  stsadm -o getproperty -pn days-to-show-new-icon -url http://Your_Server_Address



Saturday, July 21, 2012

Error Type: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.

After deploying wcf service in IIS and trying to open service we will get error message like:
"Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata."

This type of message might get when your wcf service folder out side of wwsroot folder.

Inorder to solve this problem we need to add IIS_IUSRS name to the wcf service folder's security and give read permission.

Here the steps:

1) Open your wcf service folder and right click , select properties

2) Select Security tab and click on Edit

3) Click on Add button

4) Enter IIS_USRS click on Check Names

5) Check proper permission and click on Apply and OK.

Friday, July 20, 2012

Trick and Tip: Creating a Preview Pane in a List View


Using Preview Pane you can see a List Item details on the same page. When you will move your mouse cursor on a List Item it will show you the details of that Item.

Let see how to use Preview Pane.

1) Open the List on which you want to use Preview Pane. Select "Modify View" from the List tools.

2) Under the "Style" select "Preview Pane" and press OK.

You will see that your view has been changed.

Now move your mouse cursor to any item and that item's detail will be shown on the right side in the preview pane.

Tuesday, July 17, 2012

Error Type: Server Error in '/' Application. Enabling Application Error Details in SharePoint 2010


Most of us would have encoutered the common error "Unexpected error has occured" many times  in Sharepoint 2010 which does not give any details about how and why the error occurred.

In order to know the error we need to do the follow the steps,

1. Open your webapplication's web.config and modify  CustomErrors="Off"(within System.web) and CallStack="True" which are by default set as "On" and "false" respectively.

Path : C:\inetpub\wwwroot\wss\VirtualDirectories\<<portnumber>> folder\web.config

Modify the file , save and close.

2.  Now go to this location "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\".

Open web.config in LAYOUTS folder and set CustomErrors="Off".

Save and Close the file.

Now we will see the error details in SharePoint 2010.

Error Type in Restful Service: {"error": {"code": "", "message": {"lang": "en-US", "value": "Forbidden"}}}

NOTE: Hi friends, this post related to .Net.

Here my function for update user using OData Service:


function UpdateUser(userId) {
             var updateUserdata = { UserId: 'test', FirstName: 'Accepted', LastName: 'Rejected' };
             var requestURI = USERS_ODATA_SVC + "(" + userId + ")";

             var requestOptions = {
                 requestUri: requestURI,
                 method: "PUT",
                 data: updateUserdata
             };
             OData.request(requestOptions);

         }


Am getting response error like this:

{"error": {"code": "", "message": {"lang": "en-US", "value": "Forbidden"}}}


I spent nearly 5 hours and find out the Cause for this error 

 public static void InitializeService(DataServiceConfiguration config)
        {
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);     -> here initially i gave like this, but it should be "EntitySetRights.All "
             config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        }

 this is the cause for 403 - Forbidden error in ADO.Net datasevice.

Sunday, July 15, 2012

Error Type: HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Date: Connection: close

Am getting this following error,





HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Sun, 15 Jul 2012 10:11:46 GMT
Connection: close



I figured out I had to create a site collection for the site to browse. I went and created site collection for the new web application

Central Administration > Application Management under Site Collections > Create Site Collections 

Select the web application and select a template to create site collection.

That resolved the issue.

Saturday, July 14, 2012

How to create External Content Type and List using Business Connectivity Service in SharePoint Designer 2010


1: Open your sharepoint website in sharepoint desinger 2010 and click on External Content Types in left hand side “site objects”.

2: Now Click on “External Content Type” on Ribbon.

3: Click on “Click here to discover external data sources and define operations” (showned in picture).

4: Click on Add Connection button. It will pop up “External Data Source Type selection”.

5: Select SQL Server as Data source type.Click on OK. It will pop up “SQL Server Connection”.

6: Now Enter your SQL Server Name, Database Name, and display name.
select “Connect with Impersonated Custom Identity” and enter Secure Store Application ID(remember this Application ID should be unique, will tell explain how important it is.basically it store sql server username and password). Now click on OK. 

7: After click on OK button it will ask “SQL Server username and Password”.Enter SQL Server Credentials and Click on “OK”.

8: now External content type is created. But we didnt created any operation for content type.

9: Expand Database which in Data Source Explorer.

10: Select your table which use used to fetch data and display in sharepoint list.

11: Right click on table and select “Create All Operations”.

12: Click on “NEXT”.

13: now set of all column fields will shown here. we can select all or only few. But one column sholud be unique identifier.
Click on “NEXT”.

14: Here we can filter table. Otherwise simply click on “Finish”.

15: Now we can see all operation in “External Content Type Operations”.

16: Now we can create external list.Click on “Create Lists & Form” which located on ribbon.will pop up one box.

17: Give external list name in popup box.Click on “OK”.

18: Now we can see newly create external list in “External Lists” panel.

19: Now open your site in browser.

20: Select your external list in leftside navigation.It will show error message like “Access denied by Bussiness Data Connectivity”. 

While creating external content type we given credential which are not saved anywhere those are only used for to display database in “Data source Explorer”.

21: Now Go To your central administrator and select “manage service applications” which is “Application Management” section.

22: Click on Bussiness Data Connectivity.

23: Now you can find your external content type and select your content type.

24: Now Click on “Set Object Permissions”,it will open “Set Object Permissions” pop up.

25: Enter Account name how can use this content type and Click on Add. Select Permissions Check boxes. Then Click on “OK”.

26: Now to go user website and click on ur external list. Here You will Get error message again,but this time error message is different which is “Unable to display this webpart. To troubleshoot the problem, open this web page in a microsoft sharepoint Foundation-coompatible HTML editor such as Microsoft Sharepoint Designer”.

27: GO to your central administration site and Select “Application Management” which is in Quick Launch.

28: click on “Manage Service applications” which is in “Service applications” section.

29: Now select “Secure Store Service”.

If you are using this first time it will show one message like “Before creating a new secure store target application, you must first generate a new key for this Secure store service application from the ribbon”.

30: Click on Generate new key from the ribbon.

31: Give any name which should be strong name. Click on “OK”.

32: Click on “New” on the ribbon.

33: SPecify a unique Target application id, display name,contact email(any but should be valid) and Click on “NEXT”.(Remember that This name should be already given while creating External Content Type in Step 6).

34: Click on “NEXT”.

35: Enter Target Application Administrators and Click on “OK”.

36: Now you can see newly create Target Application ID.

37: now select newly create Target Application ID and click “set” on the ribbon.

38: Enter Credentials owner(full control user like administrator), SQL server Database username and password. Click on “OK”.

39: Now go to your website and click on external list from quick launch.This time u will get list without any error.

40: this step is not require but if you get any error in previous step. GO to your central administrator–>Application Management–>Service application–>select your External content type and Click “Configure” on the ribbon.

Thursday, July 12, 2012

What are the limitations to External list using BCS in SharePoint 2010


There are a number of features that are missing when you create an External List based on an External Content Type. This can cause a lot of issues with end users because even though it looks exactly like a normal list it might not behave exactly like a normal list (or at least have some features missing)


Those are,


1. Workflows cannot be associated with external lists
2. Cannot create Information Management Policies
3. LINQ to SharePoint spmetal.exe does not support external lists
4. No Check In, Check Out. so No versioning.
5. No Inline Editing or Datasheet View
6. No ratings
7. No alerts
8. No attachments
9. No REST access through ListData.svc to External Lists
10. No RSS Feeds
11. No Item Level Permissions
12. No item or field level validation
13. No Lookups
14. No ability to Export to Excel, Create Visio Diagram, Open with Access or Open with Project.
15. Cannot use SharePoint Content Types.
16. No Managed Metadata columns for ECT

Tip : Easiest way to get assembly information




I found very interesting post which describes how to get strong name of the assembly without even opening the properties window of that assembly. I saw many fellow-developers are still not aware of this simple option that may make their life at least a bit easier, hence sharing this post.


Previously, we get assembly information by Opening the assembly(open assembly folder by windows+R and type 'assembly' then press Enter) in the GAC (c:\Windows\Assembly) and view its properties. Then form the strong name with assembly name, version and public key token.


Simplest method is,
Open the assembly, select the assembly you need the strong name for, then from the Edit menu choose Copy Display Name menu item.





Now paste it on note pad, it looks like this

Accessibility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL


Reference is here: http://blog.dotnetstep.in/2009/04/how-to-get-assembly-name-for.html

Monday, July 9, 2012

Creating a BCS External Content Type using Visual Studio 2010

BCS, Business Connectivity Service, using BCS we can connect to external databases and can display data in SharePoint list. Databases are may be SQL,MySQL, Oracle or some other. We can connect to the any external database and fetch the data. Not only displaying we can also add new records, update records and delete records.

Here i want try to show BCS operations using MySQL database.
I have one table i.e employee and it has 3 columns.
2. Now open visual studio 2010, Create new project.


3. In the left panel Select SharePoint --> 2010, select Business Data Connectivity Model from the right side panel.
4. Enter URL for debugging.
5. It will show BDC Model with default entity, now rename that entity name to 'Employee' from entity properties.
6. Now specify/rename Identity Column name to empid(it is primary key in mysql database's table) in the place of identifier.
7. Now change identifier data type to Integer by using identifier's properties.

8. Now rename Entity1.cs to EmployeeProperties, in this class we will specify all column names as properties.
9. Delete default methods for the entity.
10. Now open EmployeeProperties.cs file and specify columns as properties.
11. Now open EmployeeService.cs file and delete all methods and make sure that it looks like this.
12. Select entity and select Create Specific Finder Method from dropdown which in BDC Method details.
13. now go to BDC Explorer, Expand Employee i.e entity you can find two things one is identifier and Entity object.

expand identifier and right click select properties, change identifier and identifier Entity.

expand Entity and select entity name tab right click select properties,change type name to Properties class instance.

14. Now right click on entity name and select "Add Type Descriptor". Change Type descriptor default name to "empid" and its type name to System.Int32. And also set identifier to Empid.

15. Now again add Add Type Descriptor and change default name to EmpName, Type Name to System.String.

16. Now again add Add Type Descriptot and Change default name to EmpAddress, Type Name to System.String.
17. now again go to BDC Method Details , this time select Create Finder Method.

18. Now Again go to BDC Method details , this time select Create Creator Method.

19. Now Again go to BDC Method details, select Deleter Method from the Dropdown.
20. Go to BDC Method details Click on Add a method and select Create Updator Method from the dropdown.
Go to BDC Explorer window expand updater method,right click on primary column field and specify Pre-Updater Required to True , Read-only to false.

21. Now go to Entity's Service class i.e EmployeeService.cs. Remove all predefinded methods details and your functionality for each method which were added previous.

Here am connecting to MySQL database for that am using mysql.data.dll and adding that dll's reference to the project.
Here the code.


Now deploy the solution.
22. After successfully deployment. Go to Central Administration and click on "Manage Service applications".
23. Click on Business Data Connectivity Services from the list of Services.

24. Select your BDC name and click on Set Object permissions.
25. Assign User and give permission to that user. here am taking administrator and assign all permission to single user.
26. Open your site and create external list.

27. Specify List name and Specify external Content Type(which was created recently).
28. Now it is showing data from the external database or getting data from other than sql server here am using MySql Server.
29. Click on Empid it will show item record in display form.
30. Now am try to update the item, click on edit item and modifying field values.
31. After saving modified record updates are done on database and again data getting from the database.
32. Now click on new item from ribbon and try to insert new item.
newly added record now displaying in list.

Now am trying to delete item.


That's it. Now we can connect and fetch data from any database in SharePoint using BDC Model.

Thanks to all.