Code Snippet: How to read and modify an XML file programmatically

STEP 1: Create an XML file on your local machine 

<?xml version="1.0" encoding="utf-8"?>
<Address>
  <Address1>One Microsoft Way</Address1>
  <City>Redmond</City>
  <State>WA</State>
  <Zip>98035</Zip>
</Address>

 
(more…)

Code Snippet: How to read an XML file from a web site URL

private void button1_Click(object sender, EventArgs e)
{
    string XML_CONFIGURATION_FILE = "http://somewebserverurl/somefile.xml";
  
    Uri uri = new Uri(XML_CONFIGURATION_FILE);
    WebRequest req = WebRequest.Create(uri);
    req.UseDefaultCredentials = true;
    WebResponse response = req.GetResponse();
    Stream stream = response.GetResponseStream();
  
    XmlDocument xDoc = new XmlDocument();
    xDoc.Load(stream);
  
    XPathNavigator xNav = xDoc.CreateNavigator();
  
    tbDetails.Text += xNav.SelectSingleNode("/XMLNode/ChildNode/Element").Value.ToString();
}

 
(more…)

Setting Network Credentials when connecting to a SharePoint Web Service

I always seem to forget this and like most coders, i’d like to pull up a block of code i can copy (or snippet) and paste instead of trying to remember.

In this example, i created a web reference to the Lists.asmx web service and am wanting to (1) use my default logged in credentials or (2) specify my own. I usually want to specify my own only when i am testing a generic account or another users. You should always use the default logged in user by default instead of hard coding a user’s credentials, so please don’t do this in a production environment. (more…)