Tuesday, December 29, 2015

CRUD OPERATIONS USING SHAREPOINT 2013 RESTAPI & ANGULARJS (PART3)

First let's recap what we do in Part1 which we made an overview about technology used then we explain details about design then we finished Part2 by design all generic JavaScript we will use and layouts , all of these steps made to achieve the example below
i'm an employee in company and need to request vacation so i will log into sharepoint with my account and fill form then send vacation request , i need to see process flow where it located now or who is responsible for take an action for my task now, in other side if i'm employee who has this task now i need to respond on this task. 
In this part we will implement lists that we will save data on it then we will implement both controllers.js and services.js for vacation module to finish our Demo :)

To implement our demo we will create sharepoint list "VacationType" to store all types of vacations and "EmployeeVacation" to store submitted employee vacation.

First we will create our sharepoint lists please follow following steps :


  1. create sharepoint project "Demo.Employee".
  2. add new list item "VacationType"
  3. add new list item "EmployeeVacation"
    • add fields below to list :
      • DateFrom : date time field to store vacation start date.
      • DateTo: datetime field to store vacation end date.
      • VacationType: lookup field to "VacationType" list to set type of vacation.
    • add event receiver to list to show MyTasks functionality in our demo in this event receiver we will assign task to logged in user once item added , you can replace event receiver with your workflow process if you have.
      • code to assign task to logged in user


  4. add mapped folder to sharepoint Style Folder then create folders like image below :
    • services folder will contains all angular employee services 
      • create "EmployeeVacationService.js"
        • contain all angular controller functionality to add new vacation request.

      • create "VacationTypeService.js"
        • get data from vacation type sharepoint list

    • controllers folder will contains all angular employee controllers.
      • create "AddEmployeeVacationController.js"
        • functionality for add employee vacation request.
      • create "AssignedEmployeeVacationController.js"
        • controller to get all tasks assigned to current logged in user

    • create "DetailsEmployeeVacationController.js"
      • controller to show all details about selected vacation request.

    • create "MyEmployeeVacationController.js"
      • controller to get all vacations requested by current logged in user.

    • create "ProcessEmployeeVacationController.js"
      • controller to show the current process status of selected vacation.


  5. create visual webPart(farm solution) "EmployeeVacationWebPart" to render views
    • open "EmployeeVacationWebPartUserControl.ascx"
      • add all file references to webpart like below :

  6.  create "Pages" folder
    • add module "EmployeePagesModule"
          this module consist of page that register webpart created before on it.
      • delete sample.txt
      • add "Management.aspx" page to module
        • open page and write our magic code :

      • update Element.Xml with code below :





Finally we Finished our demo with complete step by step implementation , if you have any question you're welcome anytime .



Friday, December 4, 2015

CRUD OPERATIONS USING SHAREPOINT 2013 RESTAPI & ANGULARJS (PART2)

As we discussed in Part1 we talked about why we going to use Angularjs with Sharepoint then we decided to explain our topic by demo
i'm an employee in company and need to request vacation so i will log into sharepoint with my account and fill form then send vacation request , i need to see process flow where it located now or who is responsible for take an action for my task now, in other side if i'm employee who has this task now i need to respond on this task. 

Check Final result of  Demo  that we will do it now.

NO PAGE LOADING ANY MORE :) 

now we will start with first point which is  "Build Angularjs Structure"  , actually we have many type of structure when we start to use Angularjs but i prefer to use following structure but feel free to use your own :

Example :

  • Demo "folder under Styles SharePoint mapped folder"
    • Employee  "folder container"
      • controllers "folder container"
        • AddEmployeeController.js  "controller file"
      • services "folder container" 
        • EmployeeServices.js "services file"
    • App.js "main angularjs file"
    • Directives.js "common directive file"
    • Messages.js "file contain all common messages you will use in your project"
    • services  "folder contain most common service over project"
      • utility.js " common service file can use over project"
  • Demo "folder under Layouts SharePoint mapped file"
    • add.html  "view model"
and now we will start our demo , open your visual studio :D :D 

we will create 2 projects one for common functions and other specific for employee functionality.

first step we will create general services that we will use it over sharepoint

1- create empty SharePoint project "Demo.CommonUI" as farm solution


2- create folder "Demo" under STYLES mapped SharePoint folder (Templates > Layouts > Styles)




3- create folder "Vendor" under demo folder
we will add add library will be used in our demo under this folder.

add Angularjs framework files  under this folder you can download it through this link ,

actually i will use CDN links in my demo to save time., here is some prerequisite  libraries we will use in our project :
  • jquery
  • Angularjs : for angularjs functionality
  • ng-table : for draw tables with full functionality (feel free to use your own library)
  • toaster : for show notification after api response.
  • loader : for show loader if request required time.
  • UIBootstrap : for boot strap controls
my current vendor now will contain only files for "loader" and  i will use CDN for other libraries 
so project now will look like:



4- create some common files under "Demo" folder   :

  •  create "app.js" :
    • in code below we will handle routing of views and it's mapped controllers also we will add configuration for loader and inject all libraries that we will use in our project


  • create "Directives.js":
    • we will use it to create our own directives to use it in views, in code below i will use my custom datepicker and validation to validate FromDate & ToDate when employee submit vacation 

  • create "Messages.js":
    • we will use it centralize out used messages accross system

  • create folder "services":
    • create "baseSvc.js"
      • this file one of the most important files in our project here we will add all method GET,POST  that will call SharePoint RestApi.

    • create "UtilityService.js"
      • if you have any common function you can add it in utility.




5- now we need to create our views for all CRUD operations.
  • Add "Layouts" SharePoint mapped folder
    • create folder "EmployeeVacation" under "Demo.commonUI" folder add following files :
      • create "add.html" that will appear when employee need to request vacation
      • create "details.html" to show details about request.
      • create "MyRequests.html" to show all requests created by logged in user.

      • create "MyTasks.html" to show all tasks assigned to logged in user


      • create "process.html" to show current task status



6 - At last we are going to create our page layout 

  • create folder "PageLayouts"
    • under folder create module "PageLayouts"
      • delete sample.txt
      • add text file "DemoManagementPageLayout.aspx" then add magic code below :
      • update file "Elements.xml" with code below :









Finally we finished CommonUI Structure, congratulations :D .


















Tuesday, December 1, 2015

CRUD Operations using Sharepoint 2013 RestApi & Angularjs (Part1)

On first time joined my new job and client have only one issue with SharePoint which is staff decided to never use this portal until it come more faster, so we made a long meeting and finally we decided to use powerful of SharePoint functionality and on the same time use  powerful of  client side framework like Angularjs , from first time we knew that we will face some of challenges as when we start study and make a lot of search of how to implement Angularjs module with SharePoint RestAPI we have not a lot of references talk about it ,most of developers use knockout as client side with SharePoint so we need to take care while design our project in case that anytime we face some issues can't implemented with Angular we can use alternative way to do it even by CSOM "Client Side Object Model" and finally we made full designed structure you can use if you think to try use SharePoint and Angularjs.

I know it's long introduction but i have to explain to you what's reason that forced us to follow this strategy. And now it's time to begin ,for me the best way to learn something is to have full demo and here we are, this blog will divide into 3 parts;

  1. Build Angularjs Structure.
  2. Build Back end Structure of SharePoint and angular business layer
  3. Build generic UI project as front end interface for our demo.
now lets explain our demo will be like that :
i'm an employee in company and need to request vacation so i will log into sharepoint with my account and fill form then send vacation request , i need to see process flow where it located now or who is responsible for take an action for my task now, in other side if i'm employee who has this task now i need to respond on this task.

That's it so simple example we will start step by step on this demo to cover all business process.

And here we go, stay tuned for Part2

Sunday, March 16, 2014

Exporting the XSLT List View Web Part in SharePoint 2010

 you can’t export a XSL list view web part.
XLV Web Part With No Export Option
As you can see in the above screenshot the ability to export an XLV has been disabled by default – but that is something that you can pretty easily turn back on. Admittedly at some point here SPD has was used for the following technique – but once it’s been used (i.e. once only by me) there’s no reason that you’ll ever need it to use it again once you have the following few lines of mark-up (i.e. you don’t need it!).
So, my approach involved opening up a page with an XLV in SPD and saving the web part file locally. I then simply edited the resulting file in notepad until it looked like the below code:
<?xml version="1.0" encoding="utf-8" ?><webParts> <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> <metaData> <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <importErrorMessage>Cannot import this Web Part.</importErrorMessage> </metaData> <data> <properties> <property name="ListUrl" type="string">Lists/CustomList</property> <property name="ExportMode" type="exportmode">All</property> </properties> </data> </webPart></webParts>
With this code I can carry out the following steps to give me an XLV that can be exported:
  1. Modify the ListUrl property to the site relative url of my list
    E.g. note here that in my example it is lists/customlist not /subsite/lists/customlist
  2. Save the file locally with an appropriate filename and the extension .webpart
  3. Edit a page on the same site* as the list and upload this web part
  4. Upload A Web Part

    4. Add the web part to the page – and note the option to export is now available!
    XLV Web Part With Export Option
    5. You should now be able to edit this web part just like any other XLV, e.g. modifying the view etc.
Now that we have the ability to export an XLV it is the first step in opening up some of those great features that are available in SPD for those situations where it’s simply not possible to use SPD itself. 
*As a final thought, this works for an XLV on the same site as the list you want to show – but what about if you wanted to show a list from a different site? Well, I think in this case you could replace the ListUrl property with the ListId and the WebId properties and that may work for you. When I get a moment I’ll confirm this.

SharePoint 2010 Breadcrumb not showing sub folders in document library

SharePoint 2010 Breadcrumb not working sub folders in document library

Solution
1.      Open site in SharePoint designer 2010
2.      Open “All Files” à Select Document Library from the list à Forms à AllItems.aspx
3.      Open  “AllItems.aspx” in SharePoint Designer ( select code view )
4.      Find out  “<asp:Content ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">”
5.      Change the code
           " <SharePoint:ListProperty Property="Title" runat="server"/> "
To

<SharePoint:ListProperty Property="TitleBreadcrumb" runat="server"/>
<SharePoint:UIVersionedContent UIVersion="4" runat="server">
<ContentTemplate>
<span class="ms-ltviewselectormenuheader" runat="server">
<SharePoint:ListTitleViewSelectorMenu AlignToParent="true" id="LTViewSelectorMenu" runat="server" />
</span>
</ContentTemplate>
</SharePoint:UIVersionedContent>
</asp:Content>
6.      Save the file
7.      Refresh the SharePoint page

Creating a custom Page Layout based on ContentType in SharePoint 2010

Creating a custom Page Layout in SharePoint 2010 is not too different than creating a custom Page Layout in SharePoint 2007. However, the process of creating a SharePoint Solution Package has changed in Visual Studio 2010. This article will walk you through the steps.


First, open Visual Studio and create a new C# project, using the "Empty SharePoint Project" template, listed under the SharePoint 2010 project templates. For this example, we'll name our project "MyCustomPageLayout".




For this example, we'll be deploying our solution as a "Farm solution".



Click "Finish" to wire up your solution to your particular SharePoint site.


Content Type

First thing to do is to define a content type.
I will call my Content Type: PicturePageContentType
To do this:
- Go to: Site Settings –> Site content types
- Next, click Create
In the following screen you insert information about the content type.
An import thing to do is let it inherit from the right parent content type.
This needs to be from the group: Publishing Content Types and the parent needs to be Page.
So far nothing special, next I added some non existing columns.
On the following page click Add from new site column.
Define in the screen the follows up the columns that you would like to add to the your content type (Page Layout in the end).
After you added all the columns you needed you can overview it when you’re looking at you content type. You’ll see that I added Page Content, this was one from the already existing site columns.

 <Field ID="{7169882F-9B0C-4EA8-A096-9822C720D3BB}" Name="PageContent" DisplayName="PageContent" Type="HTML" RichText="TRUE" RichTextMode="FullHtml" />
  <Field ID="{ECD16AAB-CEA3-4D0A-9F48-16F59B29C73A}" Name="PageImage" DisplayName="PageImage" Type="Image" RichText="true" />

 
Note: If you added a from column to your page you cannot delete it:) If you want to get rid of it you need to delete the whole content type.

Create the Page Layout


As with SharePoint 2007, we'll need to provision our Page Layouts to our SharePoint Site Collection Master Page Gallery by using a "Module" element. To do this, right click on the Project and say you want to add a new item. Select "Module" from the list of SharePoint 2010 items.



We'll name the Module "masterpage". When you create the new module, you'll see something like this:



By default, the module contains a sample text file you, so you can see how the Module deploys a file to SharePoint. However, we don't need it, so we'll delete Sample.txt. Next, we need to wire up our module to point to the URL of the Master Page Gallery, so we'll add a "Url" attribute to the Module node. Our Elements.xml file should now contain this XML:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="
http://schemas.microsoft.com/sharepoint/">
  <Module Name="masterpage" Url="_catalogs/masterpage">
  </Module>
</Elements>

Next, we're going to drop our new Page Layout file into the Module. To do this, we'll right-click on the "masterpage" module in the Visual Studio explorer and select "Add new item". We're once again presented with the "Add New Item" dialog. If we were to select "Application Page" from the SharePoint 2010 menu, we'd get a code-behind page in addition to our ASPX page, which we don't want. Since all we want to provision is markup (and not code), we're going to use a shortcut. Select the "General" node and select "Text File" from the list of items. However, name the file "MyCustomPageLayout.aspx".



Add your Page Layout markup into your MyCustomPageLayout.aspx page. You can do it how I do it, which is to create a new Page Layout in SharePoint designer,

Now, we need to add the code for PageLayout1.aspx.  It's easier to design for the page first in SharePoint designer and then cop the code over.
So let's open SharePoint designer to the site you are developing on.  Select "Page Layouts" under Site Objects.

In the ribbon click "New Page Layout".  In the dialog box select Custom Content Types and ContentType1.  Enter a URL Name and Title

In the Toolbox, under SharePointControls, Server Controls, Content Fields you should see PageContent and PageImage.  Drag these two fields onto the page in the "PlaceHolderMain" content area so it looks like this

Once again, the FieldName values most likely won't match yours since that's a guid generated by the system.  We will make two changes before we copy the code over to our project.  Instead of leaving the guid for the field names we will change the FieldName to the actual names of the fields -- PageContent and PageImage so the code will be
<PublishingWebControls:RichImageField FieldName="PageImage" runat="server"></PublishingWebControls:RichImageField>
<PublishingWebControls:RichHtmlField FieldName="PageContent" runat="server"></PublishingWebControls:RichHtmlField>
This makes it easier when deploying the solution to dev, staging, and production since the FieldName guids rarely match when moving to a different SharePoint 2010 environment.
Also, in the Page directive at the top of the page get rid of the following text: meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document"
Take the code from the DesignPageLayout and copy it over to the PageLayout1.aspx page in your project.  




 then copying the code to Visual Studio. However, DO NOT FORGET to remove the attributes in the Page Directive at the top of the page that SharePoint Designer adds, that look like this:

meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document"

If you don't forget to remove those items from the Page directive, SharePoint will think your pages have been customized, even though they were deployed via a Feature.

Next, we'll need to update the Module's Elements.xml file to tell SharePoint what to do with the new Page Layout.

The first thing we'll need to do is to update the "Url" property of the File element, by removing the "masterpage/" prefix fromt the Url. (Since we already specified in the Module element that we're deploying the Page Layout to the "masterpages" library, if we left the "masterpages/" part of the Url on the file, SharePoint would try to provision our Page Layout into a library called "masterpages" inside the existing "masterpages" library! We don't want that!) Your new File element should look like this:

<File Path="masterpage\MyCustomPageLayout.aspx" Url="MyCustomPageLayout.aspx" />

Now we need to specify some properties for the Page Layout. These properties are identical to the kind of properties you would specify for a Page Layout in SharePoint 2007:
  • The Title of the file in SharePoint
    In our case, the file itself has a URL of MyCustomPageLayout.aspx, but we can also give the page a Title that will show up when the Page Layout is being selected by the content author, such as "My Custom Page Layout".
  • The Content Type
    All Page Layouts must inherit from the "Page Layout" content type (which we add using a Resource file value.)
  • Publishing Preview Image
    The Publishing Preview Image is the image that shows up when a user picks that Page Layout from the Page Layout picker while they're creating a new page. In this example, we'll just point to the Article Page's preview image.
  • The Publishing Associated Content Type
    This is the Content Type that the Page Layout is representing, such as an "Article Page", "Welcome Page", etc. The value is a string representing a Lookup value that's a combination of the name of the Content Type and its unique identifier.
Our new File node will look like this:

<File Path="masterpage\MyCustomPageLayout.aspx" Url="MyCustomPageLayout.aspx" Type="GhostableInLibrary">
      <Property Name="Title" Value="My Custom Page Layout" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
      <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/CustomPageLayout.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/CustomPageLayout.png" />
      <Property Name="PublishingAssociatedContentType" Value=";#ContentTypeName;
#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"
/>
</File>
Please note, there's no line break inside the PublishingAssociatedContentType value string; I needed to add a line break so you could see the whole value here.
That's it! We've built our Module.
Now, we're going to add a module for the Page Layout preview image. Right click on the project and add an additional Module element. Delete the "Sample.txt" file from it, and add your new preview image. (In our case, we'll call it CustomPageLayout.png".) Modify your module file so it looks like this:

<Module Name="Previews Images" Url="_catalogs/masterpage/$Resources:core,Culture;/Preview Images">
  <File Path="Preview Images\CustomPageLayout.png" Url="CustomPageLayout.png" Type="GhostableInLibrary">
      <Property Name="Title" Value="Custom Page Layout Preview Image" />
  </File>
</Module>

You might have noticed that a new Feature got created for you when you created a new Module. Let's rename the Feature itself MyCustomPageLayout in the project tree, like this:



We'll open up our MyCustomPageLayout feature, and give it a helpful name and description. Notice that you can graphically see that your Module is a part of this Feature, and you can even see which Module files will be provisioned when the Feature is activated.



The last thing we need to do is to make sure our Solution Package is getting configured correctly, to include our new Feature.

By default, the "Empty SharePoint Project" will create a DLL for you. If we just went ahead and deployed our Solution Package with the settings as-is, we would be deploying a DLL to the GAC. However, since our solution doesn't have any code in it, it would be a blank DLL. That's a bit messy, so let's avoid that. Click on the Project in your Solution Explorer, and look in the Properties Window. Change the "Include Assembly in Package" property to "False".



Important note: This value is in the Properties Window. I was originally looking for it in the Properties page of the Project (say that three times fast), and I couldn't find it there.

To deploy our new Solution Package to our Sandboxed Site, we'll go to the "Build" menu in Visual Studio, and select "Deploy MyCustomPageLayout".



This will assemble the Solution Package, deploy the Solution Package to the Sandbox, then activate the Sandboxed feature.

If we browse to our Master Page Library, we'll now see our new Page Layout. Note that, unlike SharePoint 2007, our Page Layout will appear checked out by default, if we haven't modified any of the approval or check-out settings of the out of the Master Page Gallery. We'll need to check it in and approve it for it to be available to us.



Refrences:
Links :

Error on start & end tag Page Directive ..SharePoint2010

if you face problem on tag page directive all what you need to do is Close & Open File :) , simple right ! :D

Fix for 'Load control template .. TaxonomyPicker.ascx"

if  you face problem in TexonomyPicker.ascx , please follow link below have solution :