Infopath

http://spvee.wordpress.com/2013/04/10/auto-populate-user-information-in-infopath-with-claims-based-authentication-part-3-of-3/

http://www.qdoscc.com/blog/how-automatically-retrieve-current-username-infopath-sharepoint-list-form
http://samsharepoint.wordpress.com/2013/04/30/infopath-get-the-current-user-without-writing-code/
Treeview with data Grid and context menu
output


start Program


.cs

using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using System.Text.RegularExpressions;

namespace SilverligtUsertree_RK
{
    public partial class MainPage : UserControl
    {
        ClientContext site;
        List listobj;
        ListItemCollection listcoll;
        double a, b;
        string userid = "";
        string loginuserid;

        public MainPage()
        {
            try
            {
                InitializeComponent();
                site = new ClientContext("sitename");
                site.Load(site.Web);

                listobj = site.Web.Lists.GetByTitle("User Details_RK");
                site.Load(listobj);

                CamlQuery cam = new CamlQuery();
                cam.ViewXml = "<View/>";

                listcoll = listobj.GetItems(cam);
                site.Load(listcoll);
                site.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucess), null);

                ContextMenu contex = new ContextMenu();
                contex.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                contex.VerticalAlignment = System.Windows.VerticalAlignment.Top;

                MenuItem Edit = new MenuItem();
                Edit.Header = "Edit";
                contex.Items.Add(Edit);
                MenuItem delete = new MenuItem();
                delete.Header = "Delete";
                contex.Items.Add(delete);
                MenuItem exit = new MenuItem();
                exit.Header = "Exit";
                contex.Items.Add(exit);

                Edit.Click += new RoutedEventHandler(Edit_Click);
                delete.Click += new RoutedEventHandler(delete_Click);
                exit.Click += new RoutedEventHandler(exit_Click);
                grid1.Children.Add(contex);
                grid1.Visibility = System.Windows.Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "error in mainpage");
            }

        }

        void exit_Click(object sender, RoutedEventArgs e)
        {
            grid1.Visibility = Visibility.Collapsed;
            // this.Content = new MainPage();
        }
        public void sucess(object sender, ClientRequestSucceededEventArgs args)
        {
            Dispatcher.BeginInvoke(treeview);
        }
        public void treeview()
        {
            try
            {
                // didnot look for existing item because userid is unique in list


                TreeViewItem tvitem = new TreeViewItem();//treeview the list
                tvitem.Header = "UserID";
                treeView1.Items.Add(tvitem);

                foreach (var item in listcoll)
                {
                    TreeViewItem tvi = new TreeViewItem();
                    string useridlist = Convert.ToString(item["UserID"]);
                    tvi.Header = useridlist;
                    tvitem.Items.Add(tvi);
                    tvi.MouseRightButtonDown += new MouseButtonEventHandler(tvi_MouseRightButtonDown);
                    tvi.MouseLeftButtonUp += new MouseButtonEventHandler(tvi_MouseLeftButtonUp);
                }

           
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "treeview");
            }
        }

        void tvi_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            try
            {
                TreeViewItem treevie = sender as TreeViewItem;
                loginuserid = treevie.Header.ToString();

                List<_oneuserclass> userdatagrid = new List<_oneuserclass>();//creating list our own(see below)
                foreach (ListItem item in listcoll)
                {
                    //MessageBox.Show(loginuserid + "==" + Convert.ToString(item["UserID"]));
                    if (loginuserid == Convert.ToString(item["UserID"]))
                    {

                        String result = Regex.Replace(Convert.ToString(item["Address"]), @"<[^>]*>", String.Empty);//removing the all html tags..........
                        userdatagrid.Add(new _oneuserclass
                        {

                            FirstName = Convert.ToString(item["First_x0020_Name"]),
                            LastName = Convert.ToString(item["Last_x0020_Name"]),
                            UserID = Convert.ToString(item["UserID"]),
                            Qualification = Convert.ToString(item["Qualification"]),
                            Address = result,
                            DateofBirth = Convert.ToDateTime(item["DateOfBirth"]).ToString("dd/MM/yyyy"),
                            ID = Convert.ToInt16(item["ID"]),
                            Password = Convert.ToString(item["PassWord"])

                        });
                    }

                    dataGrid1.ItemsSource = userdatagrid;
                }

            }
            catch (Exception ex)
            {
                //MessageBox.Show("error in edit" + ex.Message);
            }
        }

        void tvi_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem treevie = sender as TreeViewItem;
            userid = treevie.Header.ToString();
            //  MessageBox.Show(userid);

            e.Handled = true;
            a = e.GetPosition(treeView1).X;
            b = e.GetPosition(treeView1).Y;
            grid1.Margin = new Thickness(a, b, 0, 0);
            grid1.Visibility = System.Windows.Visibility.Visible;
        }

        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                grid1.Visibility = System.Windows.Visibility.Collapsed;
                EditingChildWindow1 editchild = new EditingChildWindow1(userid);//name of child window
                editchild.txtuserid.Text = userid;
                editchild.txtuserid.IsEnabled = true;//to keep values as default
                editchild.Show();
            }
            catch (Exception ex)
            {
            }
        }
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            grid1.Visibility = System.Windows.Visibility.Collapsed;
            MessageBoxResult result = MessageBox.Show("Are You sure want to delete the item?" + userid, "Delete item", MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK)
            {
                foreach (ListItem item in listcoll)
                {
                    string deleteuseritem = Convert.ToString(item["UserID"]);
                    if (deleteuseritem == userid)
                    {
                        int id = Convert.ToInt16(item["ID"]);
                        ListItem litem = listobj.GetItemById(id);
                        litem.DeleteObject();
                        site.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(succed), null);
                        MessageBox.Show("Hee..! hee..! hee..! your unwanted item is deleted...!");
                        this.Content = new MainPage();
                    }
                }
            }
        }
        public void succed(object sender, ClientRequestSucceededEventArgs arg)
        {

        }
        public class _oneuserclass
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Password { get; set; }
            public string UserID { get; set; }
            public string Qualification { get; set; }
            public string Address { get; set; }
            public string DateofBirth { get; set; }
            public int ID { get; set; }
        }

    }
}


Editing 


.cs
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using System.Text.RegularExpressions;

namespace SilverligtUsertree_RK
{
    public partial class EditingChildWindow1 : ChildWindow
    {
        ClientContext site;
        List listobj;
        ListItemCollection listcoll;
        string _userid;
        int ID = 0;
        public EditingChildWindow1(string userid)
        {
            InitializeComponent();
            _userid = userid;

            site = new ClientContext("sitename");
            site.Load(site.Web);

            listobj = site.Web.Lists.GetByTitle("User Details_RK");
            site.Load(listobj);

            CamlQuery cam = new CamlQuery();
            cam.ViewXml = "<View/>";

            listcoll = listobj.GetItems(cam);
            site.Load(listcoll);
            site.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucess), null);
            //this.DialogResult = true;
        } 
                private void sucess(object sender, ClientRequestSucceededEventArgs arg)
        {
            Dispatcher.BeginInvoke(editchid);
        }
        private void editchid()
        {
            ComboBoxItem combo = combo_qualifi.SelectedItem as ComboBoxItem;
            foreach (ListItem item in listcoll)
            {
                String result2 = Regex.Replace(Convert.ToString(item["Address"]), @"<[^>]*>", String.Empty);
                try
                {
                    string useridcheck = Convert.ToString(item["UserID"]);
                    string fname = Convert.ToString(item["First_x0020_Name"]);
                    string lname = Convert.ToString(item["Last_x0020_Name"]);
                    string pwd = Convert.ToString(item["PassWord"]);
                    DateTime dt = Convert.ToDateTime(item["DateOfBirth"]);
                    string qualif = Convert.ToString(item["Qualification"]);
                    string address = result2;
                   
                    if (useridcheck == _userid)
                    {
                        txtfirsrname.Text = fname;
                        txtlastname.Text = lname;
                        txtpassowrd.Text = pwd;
                        txtdateofbirth.Text =Convert.ToString(dt);
                        txtaddress.Text = address;
                        combo_qualifi.Items.Insert(0, qualif); combo_qualifi.SelectedIndex = 0;
                    }
                }
                catch { }
            }
          
        }
        
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //just inserting into the list
            ComboBoxItem combo = combo_qualifi.SelectedItem as ComboBoxItem;//we cannto add combox items directly so we use ComboBoxItem
            foreach (var item in listcoll)
            {
                try
                {
                    string useridcheck = Convert.ToString(item["UserID"]);

                    if (useridcheck == _userid)
                    {
                        int id = Convert.ToInt32(item["ID"]);
                        ID = id;
                        break;
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("insert properly" + ex.Message);
                }
            }
            ListItem items = listobj.GetItemById(ID);
            items["First_x0020_Name"] = txtfirsrname.Text;
            items["Last_x0020_Name"] = txtlastname.Text;
            items["UserID"] = txtuserid.Text;
            items["PassWord"] = txtpassowrd.Text;
            items["DateOfBirth"] = Convert.ToDateTime(txtdateofbirth.Text);
            items["Qualification"] = Convert.ToString(combo.Content);
            items["Address"] = txtaddress.Text;
            items.Update();
            site.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(sucessced), null);
            this.DialogResult = true;
        }
               public void sucessced(object sender, ClientRequestSucceededEventArgs arg)
        {
        }
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        //private void button1_Click(object sender, RoutedEventArgs e)
        //{
        //    txtfirsrname.Text = string.Empty;
        //    txtlastname.Text = string.Empty;
        //    txtpassowrd.Password = string.Empty;
        //    txtdateofbirth.Text = string.Empty;
        //    txtqualification.SelectedItem = string.Empty;
        //    txtaddress.Text = string.Empty;
        //}

    public void succed(object sender, ClientRequestSucceededEventArgs arg)
    {
    }        
    }
}

Chart dynamically==================
<UserControl x:Class="Silverligchartdynamically_RK.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

    </Grid>
</UserControl>


.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.DataVisualization.Charting;

namespace Silverligchartdynamically_RK
{
    public partial class MainPage : UserControl
    {
        List<Sale> addsale;
        public MainPage()
        {
            InitializeComponent();
            addsale = new List<Sale>();
            addsale.Add(new Sale { name="soap" ,sales=200});
            addsale.Add(new Sale {name="vegetables",sales=300 });
            addsale.Add(new Sale { name = "wheat", sales = 150 });

            Chart chartobj = new Chart();
            chartobj.Height =400;
            chartobj.Width = 400;
            //chartobj.VerticalAlignment = MouseLeftButtonDown;
            ColumnSeries colunseribj = new ColumnSeries();
            colunseribj.ItemsSource = addsale;
            colunseribj.IndependentValuePath = "name";
            colunseribj.DependentValuePath = "sales";
            chartobj.Series.Add(colunseribj);
            LayoutRoot.Children.Add(chartobj);


            //Chart chartobj2 = new Chart();
            //chartobj2.Height = 200;
            //chartobj2.Width = 200;
            //ColumnSeries colunseribj2 = new ColumnSeries();
            //PieSeries pie = new PieSeries();
            //pie.ItemsSource = addsale;
            //pie.IndependentValuePath = "name";
            //pie.DependentValuePath = "sales";
            //chartobj2.Series.Add(pie);
            //LayoutRoot.Children.Add(chartobj2);
            
        }
    }

    public class Sale
    {

        public string name { get; set; }
        public int sales { get; set; }
    }
}
CHart demo

<UserControl x:Class="Silverlighchartdemo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">

    <Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="False" Height="126" HorizontalAlignment="Left" Margin="37,50,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="290" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="114,19,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <toolkit:Chart HorizontalAlignment="Left" Margin="96,223,0,0" Name="chart1" Title="Chart Title" VerticalAlignment="Top">
            <toolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y">
                <toolkit:ColumnSeries.ItemsSource>
                    <PointCollection>
                        <Point>1,10</Point>
                        <Point>2,20</Point>
                        <Point>3,30</Point>
                        <Point>4,40</Point>
                    </PointCollection>
                </toolkit:ColumnSeries.ItemsSource>
            </toolkit:ColumnSeries>
        </toolkit:Chart>
    </Grid>
</UserControl>

.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.SharePoint.Client;
using System.Windows.Controls.DataVisualization.Charting;

namespace Silverlighchartdemo
{
    public partial class MainPage : UserControl
    {
           public string webFullURL = @"URL";

        
             List stud = null;
             ListItemCollection lists = null;
             List<Student> students = new List<Student>();

       
        private delegate void UpdateUIMethod(List<Student> studentList);

        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

       
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ClientContext spContext = ClientContext.Current;
            if (spContext == null)
            {
                spContext = new ClientContext(webFullURL);
                spContext.Load(spContext.Web);
                stud = spContext.Web.Lists.GetByTitle("StudentInfo");
                spContext.Load(stud);
                CamlQuery query = new CamlQuery();
                string strQuery = @"<View><ViewFields><FieldRef Name='AssignedTo'/>
<FieldRef Name='Name'/><FieldRef Name='Mathematics'/> 
<FieldRef Name='Physics'/><FieldRef Name='Chemistry'/>
<FieldRef Name='Computer'/></ViewFields></View>";
                query.ViewXml = strQuery;
                lists = stud.GetItems(query);
                spContext.Load(lists);
                spContext.ExecuteQueryAsync(OnSiteLoadSuccess, null);
            }
        }
        private void OnSiteLoadSuccess(object sender, ClientRequestSucceededEventArgs e)
        {
            foreach (ListItem item in lists)
            {
                Student student = new Student();
                student.Name = item["Name"].ToString();
                student.Mathematics = Int32.Parse(item["Mathematics"].ToString());
                student.Physics = Int32.Parse(item["Physics"].ToString());
                student.Chemistry = Int32.Parse(item["Chemistry"].ToString());
                student.Computer = Int32.Parse(item["Computer"].ToString());
                students.Add(student);
            }

            UpdateUIMethod up = new UpdateUIMethod(updateUI);
            this.Dispatcher.BeginInvoke(up, students);
        }

       
        private void updateUI(List<Student> tasks)
        {
            dataGrid1.ItemsSource = tasks;
            dataGrid1.SelectionMode = DataGridSelectionMode.Single;
        }
    
        public class Student
{
     public string Name { get; set; }
     public int Mathematics { get; set; }
     public int Physics { get; set; }
     public int Chemistry { get; set; }
     public int Computer { get; set; }
}

    }
}

Create a SharePoint site using REST in workflow with SharePoint Designer in office 365

SharePoint 2013 Workflows does not have any actions for creating a SharePoint sites, but you can solve this using the «call http web service» action and SharePoint REST API.
I wanted to give the users a form to order new sites in an easy way without being a site owner. I wanted to solve this using a SharePoint list with an attached workflow as a site order form.
  1. Enable Workflow can use app permissions
  2. Create a list for ordering sites
  3. Create a workflow that creates a site when new item is created
  4. Grant full control permission to workflow (needed for workflow to create site) 

Enable Workflow can use app permissions

  1. Under Settings button
  2. Select Site settings
  3. Select Manage site features
  4. Click Activate on Workflows can use app permissions

Create a list for ordering sites

  1. From your site – click Site Contents
  2. Click Add an app
  3. Click Custom list
  4. Give the new list a name like «Order project site» and click OK
We do not need any more fields for this proof of concept.

Create the workflow

  1. Click Order project site in the left menu to open your list
  2. Click List in the top menu to open list settings
  3. Click Workflow Settings in the toolbar, then click Create a Workflow in SharePoint Designer
  4. Click Allow if you get a security warning
  5. Enter a name for your workflow and click OK
  6. Rename the Stage to «Creating request header»
  7. Add a Build Dictionary action
  8. Name the output variable «RequestHeader»:
  9. Click this to add variables to the dictionary
  10. Click Add
  11. Add a string variable named content-type with the value application/json;odata=verbose and click OK
  12. Add a new string variable named Accept with the value application/json;odata=verbose and click OK
  13. Click OK
  14. Click Stage in the toolbar to create a new step
  15. Rename the stage to Creating Request Body
  16. In Stage: Creating request header set Transition to stage to Go to Creating Request Body
  17. In Stage: Creating Request Body add a new Build Dictionary action
  18. Set output to a new variable MetaData
  19. Add string variable named type with value SP.WebInfoCreationInformation
  20. Click OK to confirm all open dialog boxes
  21. Add a new Build dictionary action
  22. Set output to a new variable named RequestHeader2
  23. Add these variables to RequestHeader2:
NameTypeValue
UrlStringCurrentitem: TitleClick the fx button to add the Title of the current list item:
TitleStringCurrentitem: TitleClick the fx button to add the Title of the current list item:
DescriptionStringCurrentitem: TitleClick the fx button to add the Title of the current list item:
LanguageInteger1033
WebTemplateStringsts#0
UseUniquePermissionsStringfalse
__metadataDictionaryVariable: MetaDataClick the fx button to add the previous created MetaData variable:
  1. Click OK in all dialog boxes to save RequestHeader2 dictionary variable
  2. Add a new Build dictionary action
  3. Set output to new variable named RESTparameters
  4. Add a variable named parameters type Dictionarywith the value of the previous created RequestHeader
  5. Click OK to close all open dialogs
  6. Add a new Stage and rename it to Creating Site
  7. Set Transition to stage in Creating Request Body to go to Creating Site
  8. In Stage: Creating Site add App Step
  9. In App step add Call http web service action
  10. Click this to add the web service URL
  11. Enter the URL (use your own site and add(https://sitename.com/sitecollectionname) /_api/web/webinfos/add to it) and select HTTP Post as HTTP method:
  12. Click OK when done
  13. Select the Call HTTP web service action
  14. Click Advanced Properies in the toolbar
  15. Set RequestHeaders to variable RequestHeder and set RequestContent to variable RESTparameters:
  16. Click OK to close dialog
  17. In Stage: Creating Site set Transition to stage to go to End of Workflow
  18. Click Publish
  19. Click OK in the next dialog:
  20. Click Create site just below the Create site tab:
  21. Check Start workflow automatically when an item is created
  22. Click Publish in the toolbar and confirm if you get any warning.
Grant full control permission to workflow
The following steps must be completed by a user that is a site owner.  These actions require that a workflow has been published to the site.
  1. Click on the Settings button
  2. Go to Site Settings
  3. Under Users and Permissions, select Site app permissions
  4. Copy the client section of the App Identifier. This is the identifier between the last «|» and the «@» sign.

    Example:

  5. Navigate to the Grant permission to an app page. This must be done by browsing to appinv.aspx in the site.
    http://{hostname}/{site}/_layouts/15/appinv.aspx

    Example:


  6. Paste the client id in the App Id field and click Lookup
    Example: 

    Example:You will see complete details of the workflow app id.
  7. Paste the following Permissions Request XML to grant full control permission
       1: <AppPermissionRequests>
       2:     <AppPermissionRequest
       3:          Scope="http://sharepoint/content/sitecollection"
       4:          Right="FullControl" />

       5: </AppPermissionRequests>
Example:

  1. Click Create. You will then be asked for consent. Verify that you are asked for consent to give workflow full control of the site. If you do not see full control consent request it probably means that there was an error in the permissions request XML.
Example:

  1. Click Trust It
Your list should now create a new site each time an item is added.