Code Snippet: Using the List Field Iterator to display a list form in a SharePoint Web Part

You can use the list field iterator to show the ‘New’, ‘Edit’, and ‘Display’ form in a web part. The List Field Iterator will show all fields in your list view that you specify, and inherits the properties you specify for the view as well (such as column ordering and visible fields).

 
(more…)

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…)

Code Snippet: How to detect what browser is viewing the page

<script>
  var BROWSER_AGENT = navigator.userAgent.toLowerCase();
  if(BROWSER_AGENT.indexOf("msie") != -1) {
    //this browser is supported
  } else {
    //this browser is not supported
  }
</script>

 
(more…)

Code Snippet: Using Javascript to read the url in the address bar

<script language="javascript">
  var myURL = window.location.protocol; //returns 'http:'
  myURL += "//" + window.location.host; //returns 'http://www.sharepointdynamics.net'
</script>

 
(more…)

Code Snippet: How to get the value of a query string using the SPServices jQuery Library

Marc Anderson’s SPServices jQuery Library is a fantastic resource for the developer. Using his SPGetQueryString function, you can easily get the value of a query string parameter with only two lines of code:

var qsParams = $().SPServices.SPGetQueryString();
var qsValue = qsParams["ID"];

 The SPServices jQuery Library can be found on CodePlex.

(more…)

Code Snippet: How to read the value of a query string parameter using Javascript

//*** GET WEBID PARAMETER QUERY STRING VALUE
// example url: 'http://site/default.aspx?WebID=1234' 
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}
var qsValue = querySt("WebID");  //returns '1234'

(more…)