Wednesday, 25 July 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, 24 July 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, 21 July 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, 20 July 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, 17 July 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.