Friday, 3 January 2014

Using OAuth Providers with MVC 4 to Get Extra Data like Email Gender Bithdate


I follow step by step this  article
http://www.asp.net/mvc/tutorials/security/using-oauth-providers-with-mvc

but unfortunately i was not able to get Facebook email  , birthday and gender.

after heavy search i found out you can solve this  problem by adjusting Facebook App
permission that user will be asked for by default.

okay i will tell you how.

by default when you create an App on Facebook they will not return email and gender they just will return
 basic info (name , link ...)


if you want get  extra data like gender and birthdate you have to change the permission for the application



     after i have changed permissions in Facebook  i got the data i want from Facebook


 



Wednesday, 25 December 2013

Paging With SPDataSource - best paging ever


Paging With SPDataSource (Very Easy)


I give up from SPListItemCollectionPosition and how it works and you have to pay too much attention to last item id and .... even i wrote an article about it you can see it here (paging with splistitemcollectionposition) but not now.


Now i am gonna show you an easy way for paging in very simple steps using SPDataSource


Add Visual Web Part (Contracts)  and on code behind add

 protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (gvContracts != null)
            {
                gvContracts.PagerTemplate = null;
            }
        }

Add SPGridView

  <SharePoint:SPGridView ID="gvContracts" DataSourceID="dsContracts" GridLines="None"
               AutoGenerateColumns="false" 
                 AllowPaging="true" PageSize="2" OnPageIndexChanging="gvContracts_PageIndexChanging"
                    runat="server" ShowHeader="false" OnRowDataBound="gvContracts_RowDataBound">                         <PagerStyle CssClass="gvfooter" />
                    <Columns>
                        <%# Eval("Title")%>
                    </Columns>
                 <PagerSettings Mode="NumericFirstLast" Position="Bottom" />
                </SharePoint:SPGridView>

Add SPDataSource

 <SharePoint:SPDataSource runat="server" ID="dsContracts" DataSourceMode="List">  <SelectParameters>
   <asp:Parameter Name="WebUrl" DefaultValue="/Arabic//TendersAndContracts" />
                        <asp:Parameter Name="ListName" DefaultValue="Contracts" />
                    </SelectParameters>
                </SharePoint:SPDataSource>


run your application and see 

Notes:
you can use it in more complex situations i already did it before.
wothout this line of code (  gvContracts.PagerTemplate = null;)
the pager  will not shown.


this sample image show paging for public portal using this paging with complex search






You are welcomed for any question, just drop me comment.











Wednesday, 23 October 2013

Useful links

ASP.NET Web Pages (Razor) API Quick Reference

http://www.asp.net/web-pages/overview/more-resources/asp-net-web-pages-api-reference#Helpers




Download Companion Content for Microsoft Official Courses (MOC)

Download companion content for MOC from this page. Each course may have two related files: a zipped (.zip) file that contains content in .pdf and .xps formats, and an executable (.exe) file that contains other supplemental content.


  1. Core Solutions of Microsoft SharePoint Server 2013(20331B)
  2. Advanced Solutions of Microsoft SharePoint Server 2013 (20332B)
  3. Developing Microsoft SharePoint Server 2013 Core Solutions (20488B)
  4. Developing Microsoft SharePoint Server 2013 Advanced Solutions (20489B)
  5. Configuring and Administering Microsoft SharePoint 2010
  6. Configuring and Administering Microsoft SharePoint 2010
  7. Designing a Microsoft SharePoint 2010 Infrastructure
  8. Designing and Developing Microsoft SharePoint Server 2010 Applications

Wednesday, 19 June 2013

Common SharePoint 2010 Errors And Solutions



Common SharePoint 2010 Errors And Solutions

Error :
Restore-SPSite : Your backup is from a different version of Microsoft SharePoin
t Foundation and cannot be restored to a server running the current version. Th
e backup file should be restored to a server with version '1162887508.196608.17
694860.0' or later.
At line:1 char:15
+ Restore-SPSite <<<<  -Identity http://yousite  -Path D:\.....\....bak   -Force
    + CategoryInfo          : InvalidData: (Microsoft.Share...dletRestoreSite:
   SPCmdletRestoreSite) [Restore-SPSite], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletRestoreS
   ite

Solution:
 make sure that your backup file is not  SQL Backup  it must be SharePoint Backup

_________________________________________________________________________________

Error:
Invalid file name.


The file name you specified could not be used.  It may be the name of an existing file or directory, or you may not have permission to access the file.<nativehr>0x81020030</nativehr><nativestack></nativestack>
((

Creating Custom List template and Custom List in Sharepoint 2010 )))




Solution:

make sure the item name (File Name) for List Definition has the same name for Name property in List Template node :
 <ListTemplate  Name="RegistrationTemplate" ... />

_________________________________________________________________________________


Error:
GetUserListSchema(): Failed to get the list schema XML for feature '...', template '...': hr=0x81072101.



Solution:

feature id in list instance is wrong it should be the feature id where list is defined.
so for example if you create ListInstance (Categories) from Custom List (out of the box)
you will get this XML.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="Categories"
                OnQuickLaunch="TRUE"
                TemplateType="100"
                FeatureId="00bfea71-de22-43b2-a848-c05709900100"
                Url="Lists/Categories"
                RootWebOnly="TRUE"
                Description="">
 </ListInstance>

if for any reason you changed the  FeatureId="00bfea71-de22-43b2-a848-c05709900100" to 
 FeatureId="xxxx" you will get this error
GetUserListSchema(): Failed to get the list schema XML for feature '', template '100': hr=0x81072101.




Monday, 3 June 2013

SharePoint Error : Configure managed accounts - object reference not set to an instance of an object

When I hit the configure managed accounts link in central admin all I get is the error:

Error

SharePoint 2010 configure managed accounts Object reference not set to an instance of an object.


The Reasons for this according to the cases i faced are :
  1. Password mismatch between active directory and SharePoint ( You can use power shell command       Set-SPManagedAccount ) >>>>> powershell-script-to-change-managed-account-password
  2. There seemed to be multiple entries for the same account , this was confirmed by running power shell command Get-SPManagedAccount (Please make sure that no multiple entries for the same account ,in case there is multiple entries try to remove one of theme using Power Shell command Remove-SPManagedAccount  >>>>  Item has already been added. Key in dictionary: 'domain\account' Key being added: 'domain\account'


Please drop me a comment if you found any new reason and i will update the Post accordingly.

 

Saturday, 23 March 2013

Error when populating sharePoint 2010 Web Part Gallery

when you try to populate share point 2010 web Part Gallery an error page ( yellow page) shown

Going to Event Log show this info:


Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 3/23/2013 8:25:30 AM
Event time (UTC): 3/23/2013 5:25:30 AM
Event ID: 61c57a10998343b6ba69332e97299559
Event sequence: 9779
Event occurrence: 24
Event detail code: 0

Application information:
    Application domain: /LM/W3SVC/828672489/ROOT-1-130084692648142416
    Trust level: Full
    Application Virtual Path: /
    Application Path: C:\inetpub\wwwroot\wss\VirtualDirectories\80\
    Machine name: .........

Process information:
    Process ID: 12572
    Process name: w3wp.exe
    Account name: .....

Exception information:
    Exception type: InvalidOperationException
    Exception message: Operation is not valid due to the current state of the object.

Request information:
    Request URL: http://xxx/_layouts/newdwp.aspx
    Request path: /_layouts/newdwp.aspx
    User host address: 87.101.230.49
    User: .....
    Is authenticated: True
    Authentication Type: Federation
    Thread account name: ......

Thread information:
    Thread ID: 21
    Thread account name: ......
    Is impersonating: False
    Stack trace:    at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded()
   at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding)
   at System.Web.HttpRequest.FillInFormCollection()




To solve this problem  add the following to your web.config for your IIS web application:


<appSettings><add key=”aspnet:MaxHttpCollectionKeys” value=”2000″ /></appSettings>


where 2000 is any value the meet your need.






Sunday, 17 March 2013

Branding Shared Document Library using XSLT in SharePoint 2010 step by step


Branding Shared Document Library using XSLT in SharePoint 2010 step by step 

While working on SharePoint Portal I faced urgent need for document library
Very much like out of the box SharePoint document library and same functionality
But the problem how I can style it and gain benefits from all great functionality it has.
I know there is different ways by styling the XSLT from SharePoint Designer and apply inline style for items but unfortunately some time SharePoint designer doesn't persist changes and sometimes it’s show you unclear error messages.
To solve the problem and make my changes persist I used Visual studio 2010 and SharePoint Designer 2010 and follow the pattern of trial and error till I get the solution I am looking for.
I used IE developer tool to see the CSS class name that XSLT control render then going back to XSLT and try to find the same class name.



The solution file (click here to download) contain
  1.      XSLT file (customDocLibaray.xslt)
  2.     CSS file  (CustomDocumentLibrary.css)

 I will use Visual studio 2010 and SharePoint 2010

 Visual Studio 2010

  1. Create Empty SharePoint 2010 Project (XSLT-SharedDocument) or download.
  2. Adding Mapped Folder to XSL (Template / Layouts/XSL)
  3. Add XSLT file customDocLibaray.xslt
  4. Delete everything from the file (customDocLibaray.xslt)















SharePoint 2010

  1. Go the Web site (http://xxx/)
  2. Open the Shared Document Library in Web Browser
  3. Using Library settings create  slandered view :
    1.  View Name : CustomLibaray
    2. Select the following Column:
      1. Type (icon linked to document)
      2. File Size
      3. Name (linked to document)
  4. From Tabular view section uncheck (Allow individual item checkboxes)
  5. From section item limit   enter 5 for the number of items … this for my case , you can enter any number as you wish
  6. After creating the view you get custom view for shared document library as below image:













Go to any page and add web part from (categories >> List And Libraries >> Shared Documents)






















From the menu select  Edit Web Part , a new window appear select the view we already create (CustomLibaray) after selecting the view your web Part page will  look like the below image



























No we want start branding the Shared Document Library using SharePoint Designer 2010




  1. Open  you site (http://xxx) using SharePoint Designer 2010
  2. From Lists and Libraries select  Shared Document Library then from views select CustomLibaray
  3. Right click Edit File in Advanced mode
  4. Designer will open the view
  5. From designer select the tag WebPartPages:XsltListViewWebPart as shown in image below
  6. Then from Design Tap in top Menu in SharePoint  Designer  2010 select the menu Customize XSLT then Select Customize the Entire View as shown in image  bellow
  7. From code behind remove all ddwrt:ghost="hide"  since it’s prevent persistence changes on XSLT.
  8. On Designer select file size tag then  click edit tag as shown in image bellow ,change the class          ms-vh-div to class header-div
  9. And do the same for other headers (Name and Type).
  10. click on edit tag for header TD as bellow image:
  11. And do the same for other header cell.
Note:
Sometimes Changing the TD class on designer will not persist the changes for that you have to change it from code file XSLT.


to avoid the persistence problem open the Code File XSLT and follow below instructions: 

  1. Replace all vh-ms and vh-ms2 with value header-td
  2. In header row using designer change the class for header row by                    replacing class="{concat('ms-viewheadertr',$dirClass)}" with  value class="header-row"
  3. Replace ms-itmhover with rowhover
  4. Finally Find the following section<xsl:when test="$Position mod 2 = 0">ms-alternating</xsl:when><xsl:otherwise></xsl:otherwise> And replace it with <xsl:when test="$Position mod 2 = 0">alternaterow</xsl:when><xsl:otherwise>row</xsl:otherwise>Here we add css class for row and for alternate row.


 Summary:

You have to replace the following classes in XSLT file:

  1. header-div  replacement for  ms-vh-div 
  2. header-td  replacement  for  ms-vh2 and ms-vh
  3. row-hover replacement for rowhover
  4. alternaterow replacement for ms-alternating
  5. row is new class I add it to the gain more control on CSS
  6. if you want change (here I  did not change anything) the Pager Style you can replace the following CSS classes:
    1. ms-bottompaging
    2. ms-bottompagingline1
    3. ms-bottompagingline2




Final Steps:


  1. Copy and Paste the <xsl:stylesheet tag from SharePoint Designer to the file customDocLibaray.xslt in visual  studio
  2. Deploy solution
  3. Go back to your site (http://xxx)
  4. Edit the web Part Shared Documents
  5. From Selected view select : CustomLibary
  6. From Miscellaneous category add the link for your XSLT file (http://xxx/_LAYOUTS/XSL/customDocLibaray.xslt)
  7.  Add the css file (CustomberDocumentLibaray.css) to style library of your application then from site settings apply it as below image




You will get this fully function Document Library:






I hope that you find it useful. 
Any comment or question is more than welcomed.