Posts Tagged Reason
C# Application linked to SharePoint List Web Service
Posted by Kelly's Chronicles in .NET, C#, SharePoint on April 29, 2012
This weekend found myself knee deep in a crisis that my friend who had migrated from SharePoint 2003 to 2007 (there were reasons he couldn’t go to 2010). Simply put the migration from SharePoint 2003 to 2007 had broken his application (tracking program that submitted data to a 2003 SharePoint List) because in SharePoint 2007 you can’t do this while not on the actual server if you have “Web Page Security Validation” enabled. So for the code below you have to have SPWeb.AllowUnsafeUpdates = true; . Obviously not the ideal solution for my friend but we didn’t have time to screw around. Here is what I did….
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Xml;
using System.ServiceModel;
using System.Net;
namespace Trigger_Tracker
{
public partial class Form1 : Form
{//form move on click and drag
bool FormMoving;
Point initialPoint;
TriggerTrackerPictureBox frmPicture;
public Form1()
{//form move on click and drag
InitializeComponent();
comboBox1.SelectedIndex = 0;
FormMoving = false;
frmPicture = new TriggerTrackerPictureBox();
frmPicture.localForm = this;
frmPicture.Owner = this;
frmPicture.Show();
frmPicture.Width = 68;
frmPicture.Height = 65;
SetPositionOfPictureForm();
}
private void SetPositionOfPictureForm()
{
frmPicture.Top = this.Top + 26;
frmPicture.Left = this.Left + 87;
}
private void TrackerButton(object sender, EventArgs e)
{
string listGUID = “A93E1A7E-67D0-4D7D-A4ED-803D7DFE684B”;
string viewGUID = “6B2F3EF2-4B0C-41E1-B87E-0C3185B587DD”;
//string viewGUID2 = “6B2F3EF2-4B0C-41E1-B87E-0C3185B587DD”;
int ItemCounter = 1;
ServiceList.Lists listService = new ServiceList.Lists();
// RetentionLists.ListsSoapClient listService = new RetentionLists.ListsSoapClient();
//////
listService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
//listService.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
XmlNode activeItemData = listService.GetListItems(listGUID, viewGUID, null, null, “100”, null);
XmlDocument xDoc = new XmlDocument();
string tmpString = activeItemData.InnerXml.Replace(“\r\r”, “”);
xDoc.LoadXml(tmpString);
XmlNamespaceManager nsManager = new XmlNamespaceManager(xDoc.NameTable);
nsManager.AddNamespace(“z”, “#RowsetSchema”);
nsManager.AddNamespace(“rs”, “urn:schemas-microsoft-com:rowset”);
XmlNodeList xNode = xDoc.SelectNodes(“/rs:data/z:row”, nsManager);
foreach (XmlNode tmpNode in xNode)
ItemCounter++;
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append(“<Method ID='” + ItemCounter + “‘ Cmd=’New’>”);
strBuilder.Append(“<Field Name=’Attachments’>” + “0” + “</Field>”);
strBuilder.Append(“<Field Name=’Title’>” + PolicyNumber.Text + “</Field>”);
strBuilder.Append(“<Field Name=’Reason’>” + comboBox1.Text + “</Field>”);
strBuilder.Append(“</Method>”);
string strBatch = strBuilder.ToString();
XmlDocument newDoc = new XmlDocument();
XmlElement newElement = newDoc.CreateElement(“Batch”);
newElement.SetAttribute(“OnError”, “Continue”);
newElement.SetAttribute(“ViewName”, viewGUID);
newElement.InnerXml = strBatch;
XmlNode returnNode = listService.UpdateListItems(listGUID, newElement);
this.comboBox1.Text = “Please Select….”;
this.PolicyNumber.Text = “”;
this.PolicyNumber.Mask = “0000000000”;
comboBox1.Focus();
}
public void Form1_MouseUp(object sender, MouseEventArgs e)
{//form move on click and drag
FormMoving = false;
}
public void Form1_MouseMove(object sender, MouseEventArgs e)
{//form move on click and drag
if (FormMoving)
{
if ((Left + e.X – initialPoint.X) <= 0)
Left = 0;
else if ((Right + e.X – initialPoint.X) >= Screen.PrimaryScreen.Bounds.Right)
Left = Screen.PrimaryScreen.Bounds.Right – Width;
else
Left = Left + e.X – initialPoint.X;
if ((Top + e.Y – initialPoint.Y) <= 0)
Top = 0;
else if ((Bottom + e.Y – initialPoint.Y) >= Screen.PrimaryScreen.Bounds.Bottom)
Top = Screen.PrimaryScreen.Bounds.Bottom – Height;
else
Top = Top + e.Y – initialPoint.Y;
}
SetPositionOfPictureForm();
}
public void Form1_MouseDown(object sender, MouseEventArgs e)
{//form move on click and drag
FormMoving = true;
initialPoint = new Point(e.X, e.Y);
}
public void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{//form move on click and drag
FormMoving = true;
initialPoint = new Point(e.X, e.Y);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
}
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
}
public void label1_MouseHover(object sender, EventArgs e)
{
FormMoving = false;
}
public void label1_MouseUp(object sender, MouseEventArgs e)
{
FormMoving = false;
}
public void Form1_MouseHover(object sender, EventArgs e)
{
this.Opacity = 1;
}
public void Form1_MouseLeave(object sender, EventArgs e)
{
if(!PolicyNumber.Focused)
this.Opacity = .25;
}
public void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.Opacity = 1;
}
public void pictureBox1_MouseHover_1(object sender, EventArgs e)
{
this.Opacity = 1;
}
public void Form1_Click(object sender, EventArgs e)
{
comboBox1.Focus();
}
}
}
.NET Framework, 2003, 2010, activeItemData, AddNamespace, AllowUnsafeUpdates, Append, Application, Attachments, Batch, Bottom, Bounds, c#, ChannelFactory, ClientCredential, Collections, ComponentModel, Continue, CreateElement, CredentialCache, Credentials, crisis, csharp, Data, DefaultNetworkCredentials, EventArgs, Field, Focus, Form, Forms, friend, Generic, GetListItems, InitializeComponent, initialPoint, InnerXml, ItemCounter, knee, Left, Linq, List, listGUID, Lists, listService, ListsSoapClient, LoadXml, Mask, method, migration, MouseEventArgs, Name, NameTable, nsManager, OnError, Owner, PAGE, Point, PolicyNumber, Reason, Replace, RetentionLists, RowsetSchema, schemas, Select, SelectedIndex, SelectNodes, sender, server, Service, ServiceList, ServiceModel, SetAttribute, SetPositionOfPictureForm, SharePoint, solution, SPWeb, StringBuilder, System, Text, Title, TrackerButton, TriggerTrackerPictureBox, Trigger_Tracker, UpdateListItems, Validation, viewGUID, ViewName, Web Page Security, Width, Windows, xDoc, XmlDocument, XmlElement, XmlNamespaceManager, XmlNode, XmlNodeList, xNode
Archives
- April 2018
- January 2018
- December 2017
- June 2017
- May 2017
- May 2016
- April 2016
- September 2015
- July 2014
- June 2014
- November 2012
- October 2012
- June 2012
- May 2012
- April 2012
- January 2012
- September 2011
- August 2011
- July 2011
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- August 2008
- July 2008
- June 2008
- May 2008
Recent Comments