Create a empty Sharepoint solution and add a Visual Web Part.
Step 2
Create a Datatable from SharePoint List
Step 3
Create and fill SPGridView using the datatable.
Regards.
Oscar Miguel Dominguez Acevedo.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WCFInsertItem
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
void InsertItemInList(string UrlWebApplication, string ListName, string TitleItem);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.SharePoint;
namespace WCFInsertItem
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public void InsertItemInList(string UrlWebApplication, string ListName, string TitleItem)
{
using (SPSite site = new SPSite(UrlWebApplication))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList oList = web.Lists[ListName];
SPItem oItem = oList.Items.Add();
oItem["Title"] = TitleItem;
oItem.Update();
web.AllowUnsafeUpdates = false;
}
}
}
}
}
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using WCFInfopathForm.WCFService;
namespace WCFInfopathForm
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
// NOTE: The following procedure is required by Microsoft InfoPath.
// It can be modified using Microsoft InfoPath.
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL2_5"]).Clicked += new ClickedEventHandler(CTRL2_5_Clicked);
}
public void CTRL2_5_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.
Service1 WCFInfopath = new Service1();
WCFInfopath.Credentials = System.Net.CredentialCache.DefaultCredentials;
XPathNavigator ValueInfo = this.MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:field1", this.NamespaceManager);
String ValueText = ValueInfo.Value;
WCFInfopath.InsertItemInList("http://labwfos2010/sites/ejemplossharepoint/", "ItemsSharePoint", ValueText);
}
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace ProyectosSharePoint.LeerItems
{
public partial class LeerItemsUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb Web = SPContext.Current.Web;/// web context
SPList List = Web.Lists["ItemsSharePoint"]; ///Name of list
foreach (SPItem item in List.Items)
{
string ItemValue = item["Title"].ToString();///value of the field
}
}
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using Microsoft.SharePoint;
using System.IO;
namespace ProyectosSharePoint.UpdateXml
{
public partial class UpdateXmlUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); /// New Xml Document
SPWeb web = SPContext.Current.Web; /// current context
SPFolder FolderXML = web.GetFolder("Formulaio"); /// folder name
foreach (SPFile File in FolderXML.Files)
{
byte[] XmlFormData = File.OpenBinary();/// open file
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
using (MemoryStream ms = new MemoryStream(XmlFormData))
{
MemoryStream ms2 = new MemoryStream();
xmldoc.Load(ms);/// load Xml
XmlNodeList nodes = xmldoc.GetElementsByTagName("my:Email");/// Node
nodes.Item(0).InnerText = TextBox1.Text;/// Update Node with textbox value
xmldoc.Save(ms2);///Save xmldoc in new MemoryStream ms2
ms.Close();/// close
File.SaveBinary(ms2);/// save file with new MemoryStream
}
}
}
}
}