Wednesday, 5 June 2013

Filtering SharePoint List data dynamically in Webpart

Add below Namespaces into the Standard WebPart:

using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Xml;  namespace DynamicallyFilterationList.ListFilterationDynamically
{
    [ToolboxItemAttribute(false)]
    public class ListFilterationDynamically : System.Web.UI.WebControls.WebParts.WebPart
    {
        TextBox tbA;
        TextBox tbB;
        Button filterButton;
        UpdatePanel mainUpdatePanel;
        ListViewWebPart lvwp;
        SPList list;        protected override void CreateChildControls()
        {            mainUpdatePanel = new UpdatePanel();
            mainUpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;            tbA = new TextBox();
            tbB = new TextBox();            list = SPContext.Current.Web.GetList(SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, "Lists/FilterList"));
            lvwp = new ListViewWebPart();
            lvwp.ListName = list.ID.ToString("B").ToUpper();
            lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
            lvwp.ChromeType = PartChromeType.None;             filterButton = new Button();
            filterButton.Text = "Filter";
            filterButton.Click += new EventHandler(filterButton_Click);             Controls.Add(new LiteralControl(" Nom : "));
            Controls.Add(tbA);
            Controls.Add(new LiteralControl(" Prenom : "));
            Controls.Add(tbB);
            mainUpdatePanel.ContentTemplateContainer.Controls.Add(filterButton);
            mainUpdatePanel.ContentTemplateContainer.Controls.Add(lvwp);
            this.Controls.Add(mainUpdatePanel);
        }        private void filterButton_Click(object sender, EventArgs e)
        {
            string query = string.Empty;
            string tempAdding = string.Empty;
            if (!string.IsNullOrEmpty(tbA.Text))
            {
                query = "<Contains><FieldRef Name='LinkTitle' /><Value Type='Text'>" + tbA.Text + "</Value></Contains>";
            }
            if (!string.IsNullOrEmpty(tbB.Text))
            {
                tempAdding = "<Contains><FieldRef Name='Prenom' /><Value Type='Text'>" + tbB.Text + "</Value></Contains>";
                query = (query.Length > 0 ? "<And>" + query + tempAdding + "</And>" : tempAdding);
            }            XmlDocument doc = new XmlDocument();
            doc.LoadXml(lvwp.ListViewXml);
            XmlNode queryNode = doc.SelectSingleNode("//Query");
            XmlNode whereNode = queryNode.SelectSingleNode("Where");            if (whereNode != null) queryNode.RemoveChild(whereNode);
            XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Where", String.Empty);
            newNode.InnerXml = query.ToString();
            queryNode.AppendChild(newNode);
            lvwp.ListViewXml = doc.OuterXml;        }
    }
}
Ref: http://christopherclementen.wordpress.com/2012/04/02/filter-a-list-dynamically/ OutPut Screen:
Chart Webparts Creation using Visual Studio in SharePoint 2010

http://social.technet.microsoft.com/wiki/contents/articles/17614.adding-charts-to-standard-webparts-and-visual-webparts.aspx


Note: Modified below things as per environment

1)  Add "ChartImageHandler" in system.WebServer handlers tag inside:

So the simple solution that worked for me was just to remove the following entry from web.config <system.web> section:

<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35"
validate="false"/>
</httpHandlers>

Also make sure that <system.webServer> section has the following:

<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,
System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
 

Ref:  http://asifhuddani.wordpress.com/2010/10/07/chart-control-asp-net-4-0-and-iis-7-problem/

OutPut Screen:

 

Monday, 29 April 2013

Blank Site Template is missing in SharePoint 2013



First, there's still possible to create blank sites by using PowerShell:
  1. Run the command Get-SPWebTemplate to get the full list of the available templates. You can see, the Blank Site template is still there, and it's ID is STS#1:
  2. From this point, creating a new site collection is as easy as this:
    $template = Get-SPWebTemplate "STS#1"
    New-SPSite -Url "<URL for the new site collection>" -OwnerAlias "<domain\user>" -Template $template

Second, Just go to the folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\1033\XML, and open the WEBTEMP.XML file. There, you'll find a line like this:
<Configuration ID="1" Title="Blank Site" Hidden="TRUE" ImageUrl="/_layouts/15/images/stbs.png?rev=23" Description="A blank site for you to customize based on your requirements." DisplayCategory="Collaboration" AllowGlobalFeatureAssociations="False" > </Configuration>
Here you go: just change the highlighted tag from Hidden="TRUE" to Hidden="FALSE", save the file, and that's it: next time you want to create a new site, you'll get the Blank Site Template:
Export/Import SharePoint Terms Store using PowerShell Commands


Export-SPTerms and Import-SPTerms:
Exporting and importing spterms needs extra cmdlets, for getting extra set of cmdlets you will deploy wsp file into your sharepoint environement. You can get wsp file from
http://www.thelapointes.com/blog/Lapointe.SharePoint2010.Automation.wsp
After deploying wsp file , verify cmdlets added or not
  • Go to Sharepoint management console
  • Type Export-SPTerms (or) Import-SPTerms if your asked for any information then your cmdlets if you get error terms cmdlets are not added.
For exporting the spterms excute following command :

Export-SPTerms -TaxonomySession "Central admin url" -OutputFile "Your xml file path"
Ex:Export-SPTerms -TaxonomySession "http://myadmin:2324/" -OutputFile "c:\terms.xml"
This will export spterms to xml file you have mentioned.

For importing spterms(collected from other source) from xml :
Before import you just need change 3-parameters in the source xml provided.Theyare
  1. Open the source xml, in that node(Termstore under the node Termstores) has name attribute, the name attribute value and your local Managed metada source must be same.If not change it as per your local term store name
  2. Change Id attribute and give the id of your local Termstore
  3. Change SystemGroup attribute value to your local system group
Ex : <TermStore Name="Your local Metadata Service" Id="Local store id guid" IsOnline="True" WorkingLanguage="1033" DefaultLanguage="1033" SystemGroup="local store system group id">

Note: Above 3-steps you can easily do by exporting your local terms to xml and from the resulted xml copy all these 3-attributes.

And also change the user field values in the source xml to your local users(in the store system where your exporting)

Thursday, 25 April 2013


Debugging PowerShell Script

Go to Programs - > Accossaries -> Windows PowerShell -> Windows PowerShell ISE -> Drag your script file -> Toggle breakpoint (F9) and click on Debug F5.

 

Wednesday, 24 April 2013

Creating a Sequential Workflow in Visual Studio 2010


To create the Projects SharePoint document library
  1. On the Site Actions menu, click More Options.
  2. In the installed items list, click Document Library.
  3. On the right side of the screen, in the name box, type Projects and then click Create.
create-projects
——————————————————————————————————
Once you have your Projects library created, add a document status column to it.

To create the document status column

  1. Browse to the Projects documents library.
  2. On the Ribbon, in the Library Tools tab group, click the Library tab.
  3. On the Ribbon, click Create Column.
  4. In the Column Name text box, type Document Status.
  5. In the Type option box, click Choice.
  6. In the Type each choice on a separate linemultiline text box, type:
    • Review Needed
    • Changes Requested
    • Review Complete
    Check the spelling for these options as a text match will be used in the code.
    document-stats-column
  7. In the Default value text box, click the box, ensure that Review Needed is specified, and then click OK.
  8. On the Ribbon, click Create Column.
  9. In the Column Name text box, type Assignee.
  10. In the Type option box, click Single line of text, and then click OK.
  11. On the Ribbon, click Create Column.
  12. In the Column Name text box, type Review Comments.
  13. In the Type option box, click Multiple lines of text, and then click OK.
Once that’s complete, you’re ready to start on developing the workflow so open up Microsoft Visual Studio 2010.

To create a SharePoint 2010 sequential workflow application solution in Visual Studio 2010

  1. On the File menu, click New, and then click Project.
  2. In the Installed Templates section, expand either Visual Basic or C#, expand SharePoint, and then click 2010.
  3. In the template pane, click Sequential Workflow.
  4. In the Name text box, type seqWorkflow.new-seq-workflow
  5. Leave other fields with their default values and then click OK.
  6. In the What local site do you want to use for debugging? list, select your site, and then click Next.sharepoint-customization-wizard
  7. On the Specify the workflow name for debugging page, leave the default name, select List Workflow, and then click Next.name-workflow
  8. On the Select the lists you will use when debugging page, click The library or list to associate your workflow with drop-down, and then click Projects.lists
  9. Leave the other options with their default settings and click Next.
  10. On the Specify the conditions for how your workflow is started page, click Finish.workflow-conditions

You should now see a simple workflow in your Visual Studio window.
workflow-chart

To configure the workflow

  1. With the design surface open, click the onWorkflowActivated1 activity.
  2. In the Properties window for the onWorkflowActivated activity, in the Invoked property, click the empty text box, and type onWorkflowActivated. On the keyboard, press Enter.workflow-properties
  3. Reopen the design surface using the tab on the main page.
  4. With the design surface on screen, open the toolbox on the left-hand side of the screen. In the Windows Workflow 3.0 group, click the While activity, and drag it underneath the onWorkflowActivated1 activity.workflow-toolbox
  5. Click the While activity on the design surface. Then, in the Properties window for the activity, in the Condition row, click (none).
  6. In the drop-down selection box, click Code Condition.code-condition
  7. In the Condition row, click the expand indicator [+], and in the expanded condition row, type isWorkflowPending and then press Enter.
  8. Reopen the design surface using the tab on the main page.
  9. In the toolbox, from the SharePoint workflow group, drag OnWorkflowItemChanged and drop to the Drop an Activity Here text in the While activity.onworkflowitemchanged
  10. Click the OnWorkflowItemChanged activity, and then in the Properties window, in the CorrelationToken property, click the empty text box.
  11. On the drop-down selection box, click workflowToken.
  12. In the Properties window, in the Invoked property, click the empty text box, type onWorkflowItemChanged, and then press Enter.workflow-token
  13. Replace the code in the Workflow1 code file with the following code:
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Workflow.ComponentModel.Compiler
Imports System.Workflow.ComponentModel.Serialization
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Design
Imports System.Workflow.Runtime
Imports System.Workflow.Activities
Imports System.Workflow.Activities.Rules
Imports Microsoft.SharePoint.Workflow
Imports Microsoft.SharePoint.WorkflowActions

' NOTE: When changing the namespace; please update XmlnsDefinitionAttribute ' in AssemblyInfo.vb 
Public Class Workflow1
    Inherits SequentialWorkflowActivity
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub

    Dim bIsWorkflowPending As Boolean = True

    Public workflowProperties As SPWorkflowActivationProperties = _
        New Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties

    Private Sub onWorkflowActivated(ByVal sender As System.Object, _
        ByVal e As System.Workflow.Activities.ExternalDataEventArgs)
        CheckStatus()
    End Sub

    Private Sub isWorkflowPending(ByVal sender As System.Object, _
        ByVal e As System.Workflow.Activities.ConditionalEventArgs)
        e.Result = bIsWorkflowPending
    End Sub

    Private Sub onWorkflowItemChanged(ByVal sender As System.Object, _
        ByVal e As System.Workflow.Activities.ExternalDataEventArgs)
        CheckStatus()
    End Sub

    Private Sub CheckStatus()
        If CStr(workflowProperties.Item("Document Status")) = "Review Complete" Then
            bIsWorkflowPending = False
        End If
    End Sub
End Class

To deploy the project

  1. In Solution Explorer, right-click the project, and then click Deploy.deploy-solution
  2. Open the SharePoint home page.
  3. On the Quick Launch menu, click Projects, and then click Add document.
  4. In the Upload Document dialog box, click Browse, select a document, and then click Open. I created a Test.txt document using notepad to use for this workflow purpose.test-document
  5. In the Upload dialog box, click OK.
  6. Provide details for the uploaded document, ensure that the Document Status is set to Review Needed, and then click Save.projects-test
  7. Note that the “seqworkflow” column is set to In Progress.
  8. Edit the properties for the item, change the Document Status to Review Complete, and then click Save.
  9. Note the “seqworkflow” column is now set to Completed.
workflow-complete
Congratulations you’ve completed your basic Sequential Workflow! :)
The Sequential Workflow project type in Visual Studio 2010 provides a graphical design surface on which a workflow can be constructed.
  • A While workflow activity is added to the workflow.
  • The While condition is configured as a Code Condition, and the code routine isWorkflowPending is specified.
  • The methods onWorkflowItemChanged() and onWorkflowActivated() are configured to call aCheckStatus() method that sets the bIsWorkflowPending to false if the document has the status “Review Completed”.
  • Using a Code Condition, the While activity is terminated by setting a Boolean flag e.Result to True or False.True continues the While condition. False exits the While condition and allows the workflow to continue until it is completed.

Adding Custom Asp.net pages into SharePoint using Layout Folder approach

 

Layout Folder approach is one of the methods of integrating files into Share Point Site .This document explains the steps for adding Custom asp.net Pages to _layout folder using Layout Folder approach.


Advantages

Following are the advantages when we add Custom Aspx Pages into Share Point Site
· End users can perceive all those pages within SharePoint site. She/he must not go to a separate web application URL.
· No additional Work needs to be done once the integration is done.
· Share Point Security and access rules will take care of everything.
· No additional Authorization and Authentication mechanism needs to be done.
· Development Efforts are less compared to developing Web Parts.


Solutions

Following are few solutions in which we can integrate Custom Aspx Pages into Share Point Site
1. SharePoint designer approach: This approach is better when we work with few aspx pages and less functionality.
2. Web Parts approach: This can be used in combination with SharePoint designer. But once again, developing many web parts is not feasible solution and sometimes leads to performance issues.
3. _Layouts folder approach: This is best and simple method of all. This method deploys the web application pages under the _layouts folder of Share Point Site and the pages can be accessed from any Share Point Site.

Steps
Following are the steps how to add Custom aspx or asp.net Pages in Share Point Site

Step 1: Open Visual Studio 2010 and create an Empty Share point Project named as“AspxToLayouts”






Step 2: Select“Deploy as Farm solution”.


Step 3: Right click on the Project and add navigate to “Add -> SharePoint “Layouts” Mapped Folder”.






Step 4: After adding, Layouts folder structure will be generated in your project. After that we will add our newly custom aspx page to the Layouts folder that got generated in our project. Sometimes we can add existing Aspx also if required.


Step 5: Hence to add a new aspx page, Right click on your custom folder “AspxToLayouts” and click on “Add -> New Item”. Following, In Add new item menu under “General” tab select “Text file” and rename it as“MyPage.aspx”. See the screen shot below




Step 6:
Now your Project structure should look something like below screen shot.




Also, in the above screen verify the“Deployment Path” for newly created Page. To verify Traverse to “MyPage.aspx”-> Properties window.

Step7:Next, in solution explorer right clicks the Project and Build & Deploy.


Step 8: Once it is deployment is done successfully, traverse to your 14 hive folder and validate that new folder “AspxToLayouts”generated with our custom page “MyPage.aspx” in it.