Archive

Posts Tagged ‘SilverLight’

Retrieving list data in SilverLight

What is the difference between SharePoint 2010 and 2013 Client object model


What is the difference between SharePoint 2010 and 2013 Client object model

http://microsoft-techies.blogspot.com/2014/03/what-is-difference-between-sharepoint.html

Silverlight Samples

SharePoint 2010 SilverLight


Silver Light read xml file

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Linq;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Windows.Media.Imaging;

namespace LowIntegrationSLApp
{
public partial class MainPage : UserControl
{
string promotion = “”;
string fastTrack = “”;
double avgScore = 0.0;

List<Employees> myEmployeeList = new List<Employees>();

public MainPage()
{
// Required to initialize variables
InitializeComponent();
}

private void btnRefresh_Click(object sender, RoutedEventArgs e)
{
XElement employee = XElement.Load(@”Employee.xml”);
resetThermometer();
string tempEmpName = “”;
string tempEmpID = “”;
string tempFY08 = “”;
string tempFY09 = “”;
string tempFY10 = “”;

var employees =
from emp in employee.Elements(“Employee”)
select new
{
tempEmpName = (string)emp.Element(“Name”),
tempEmpID = (string)emp.Element(“EmpID”),
tempFY08 = (string)emp.Element(“FY08”),
tempFY09 = (string)emp.Element(“FY09”),
tempFY10 = (string)emp.Element(“FY10”)
};

foreach (var item in employees)
{
Employees tempEmployee = new Employees();
tempEmployee.empName = item.tempEmpName.ToString();
lstbxEmployeeNames.Items.Add(tempEmployee.empName);
tempEmployee.empID = item.tempEmpID.ToString();
tempEmployee.empFY08 = item.tempFY08.ToString();
tempEmployee.empFY09 = item.tempFY09.ToString();
tempEmployee.empFy10 = item.tempFY10.ToString();
myEmployeeList.Add(tempEmployee);
}
}

private void lstbxEmployeeNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
resetThermometer();

string tempEmpID = “”;
string tempFY08 = “”;
string tempFY09 = “”;
string tempFY10 = “”;

string empFilter = lstbxEmployeeNames.SelectedItem.ToString();

var expr =
from emp in myEmployeeList
select new
{
emp.empName,
emp.empID,
emp.empFY08,
emp.empFY09,
emp.empFy10
};
foreach (var item in expr)
{
if (item.empName == empFilter)
{
txtbxEmplID.Text = item.empID;
txtbxFY08.Text = item.empFY08;
txtbxFY09.Text = item.empFY09;
txtbxFY10.Text = item.empFy10;
}
}
}

private void btnCalc_Click(object sender, RoutedEventArgs e)
{
resetThermometer();
double rvwFY08 = Double.Parse(txtbxFY08.Text);
double rvwFY09 = Double.Parse(txtbxFY09.Text);
double rvwFY10 = Double.Parse(txtbxFY10.Text);

avgScore = Math.Round(((rvwFY08 + rvwFY09 + rvwFY10) / 3), 2) * 100 / 100;

if (avgScore >= 4.5)
{
promotion = “Yes”;
fastTrack = “Yes”;
shapeRectanglePromo.Height = 3;
}
else if (avgScore >= 4.0)
{
promotion = “Yes”;
fastTrack = “No”;
shapeRectangleNoPromo.Height = 3;
}
else
{
promotion = “No”;
fastTrack = “No”;
shapeRectangleLowScore.Height = 3;
}

txtbxPromo.Text = promotion;
txtbxFastTrack.Text = fastTrack;
txtbxAVGScore.Text = avgScore.ToString();
}

private void resetThermometer()
{
shapeRectanglePromo.Height = 0;
shapeRectangleNoPromo.Height = 0;
shapeRectangleLowScore.Height = 0;
}
}
}

———-

xml file

 

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Employees>
<Employee>
<Name>John Doe</Name>
<EmpID>837901</EmpID>
<FY08>3.2</FY08>
<FY09>3.4</FY09>
<FY10>3.8</FY10>
</Employee>
<Employee>
<Name>Kelly Jackson</Name>
<EmpID>983011</EmpID>
<FY08>2.8</FY08>
<FY09>2.9</FY09>
<FY10>3.0</FY10>
</Employee>
<Employee>
<Name>Sam Sheppard</Name>
<EmpID>10290</EmpID>
<FY08>4.2</FY08>
<FY09>4.3</FY09>
<FY10>4.5</FY10>
</Employee>
<Employee>
<Name>Lamont Smyth</Name>
<EmpID>129775</EmpID>
<FY08>3.8</FY08>
<FY09>3.6</FY09>
<FY10>3.2</FY10>
</Employee>
<Employee>
<Name>Beth Canyon</Name>
<EmpID>38921</EmpID>
<FY08>2.1</FY08>
<FY09>2.2</FY09>
<FY10>2.0</FY10>
</Employee>
<Employee>
<Name>Barry McCathry</Name>
<EmpID>201982</EmpID>
<FY08>3.3</FY08>
<FY09>2.9</FY09>
<FY10>3.7</FY10>
</Employee>
<Employee>
<Name>Steve Denn</Name>
<EmpID>290122</EmpID>
<FY08>4.5</FY08>
<FY09>4.6</FY09>
<FY10>4.5</FY10>
</Employee>
<Employee>
<Name>Ahmed Habul</Name>
<EmpID>0992812</EmpID>
<FY08>3.9</FY08>
<FY09>3.8</FY09>
<FY10>3.9</FY10>
</Employee>
</Employees>

 

SharePoint SilverLight

SharePoint list update using SilverLight


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.SharePoint;

namespace SPListApp
{
public partial class MainWindow : Window
{
string strSPSiteURL = “”;
string strSPListName = “”;
string strProductName = “”;
string strProductSKU = “”;
string strProductPrice = “”;

public MainWindow()
{
InitializeComponent();
}

private void btnExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}

private void btnClear_Click(object sender, RoutedEventArgs e)
{
txtbxListName.Text = “”;
txtbxSPURL.Text = “”;
txtbxProdName.Text = “”;
txtbxProductSku.Text = “”;
txtbxProductPrice.Text = “”;

}

private void btnLoad_Click(object sender, RoutedEventArgs e)
{
strSPSiteURL = txtbxSPURL.Text;
strSPListName = txtbxListName.Text;
strProductName = txtbxProdName.Text;
strProductSKU = txtbxProductSku.Text;
strProductPrice = txtbxProductPrice.Text;

using (SPSite site = new SPSite(strSPSiteURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;

SPList list = web.Lists[strSPListName];
SPListItem Item = list.Items.Add();
Item[“Title”] = strProductName;
Item[“Product_SKU”] = strProductSKU;
Item[“Price”] = strProductPrice;
Item.Update();
}
}

}
}}

 

SP List App using SIlverlight

SharePoint 2010 Add new item to a list using Web Services


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;

namespace WPFSPListApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
string strCompanyName = “”;
string strRegion = “”;
string strSize = “”;
string strSales = “”;
string strListID = “”;
string strViewID = “”;

public MainWindow()
{
InitializeComponent();
}

private void btnUpdate_Click(object sender, RoutedEventArgs e)
{

strCompanyName = txtbxCompanyName.Text;
strRegion = txtbxRegion.Text;
strSize = txtbxSize.Text;
strSales = “$” + txtbxSales.Text;

WPFSPListApp.MySPWebService.Lists myListService = new MySPWebService.Lists();
myListService.Credentials = System.Net.CredentialCache.DefaultCredentials;
myListService.Url = “http://SERVER:8888/_vti_bin/Lists.asmx&#8221;;

//Create list name as: Customers
//Add Columns: Region, Size, Sales
XmlNode myListView = myListService.GetListAndView(“Customers”, “”);
strListID = myListView.ChildNodes[0].Attributes[“Name”].Value;
strViewID = myListView.ChildNodes[1].Attributes[“Name”].Value;

XmlDocument myListDoc = new XmlDocument();
XmlElement batchXML = myListDoc.CreateElement(“Batch”);
batchXML.InnerXml = “<Method ID = ‘1’ Cmd=’New’><Field Name=’Title’>” + strCompanyName + “</Field><Field Name=’Region’>” + strRegion + “</Field><Field Name=’Size’>” + strSize + “</Field><Field Name=’Sales’>” + strSales + “</Field>” + “</Method>”;

XmlNode myListReturn = myListService.UpdateListItems(strListID, batchXML);
MessageBox.Show(“SharePoint List was updated!”);
}

private void btnClear_Click(object sender, RoutedEventArgs e)
{
txtbxCompanyName.Text = “”;
txtbxRegion.Text = “”;
txtbxSales.Text = “”;
txtbxSize.Text = “”;
}

private void btnExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
}
}

Download below file…

SharePoint 2010 List Object Model Code

SharePoint 2010 Add new item to list using Web Services usingĀ Silver Light

=============================================================

Update List Using Server Side object model code

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace ServerSideObjectModel.WriteDataWebPart
{
[ToolboxItemAttribute(false)]
public class WriteDataWebPart : WebPart
{
Button btnAddData = new Button();
Label lblStatus = new Label();
Label lblResults = new Label();

string strSPSiteURL = “http://intranet.contoso.com&#8221;;
string strSPListName = “Products”;
string strProductName = “Bauer 5000”;
string strProductSKU = “BR-0290”;
string strProductPrice = “$369.99”;

protected override void CreateChildControls()
{
btnAddData.Text = “Add Data”;
lblStatus.Text = “Status: “;
lblResults.Text = “In Progress”;
this.Controls.Add(lblStatus);
this.Controls.Add(lblResults);
this.Controls.Add(btnAddData);
btnAddData.Click += new EventHandler(btnAddData_Click);

}

void btnAddData_Click(object sender, EventArgs e)
{
using (SPSite site = new SPSite(strSPSiteURL))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;

SPList list = web.Lists[strSPListName];
SPListItem Item = list.Items.Add();
Item[“Title”] = strProductName;
Item[“Product_SKU”] = strProductSKU;
Item[“Price”] = strProductPrice;
Item.Update();

web.AllowUnsafeUpdates = false;
}
}
lblResults.Text = “Done”;
}
}
}