How to get all ‘Inherited Security’ sites in your SharePoint site collection

This article is nothing new to SharePoint developers. In fact, there are better options of getting a listing of all subsites in your site collection. However, for those who are not experienced developers, this article will give you an idea of what you can do with the SharePoint web services.

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

How to add a new item to a SharePoint list using Javascript and the Lists.asmx web service

I had an idea at the beginning of the year. I am the Site Collection Administrator and am only responsible for administering and developing solutions for my SharePoint site collection in my office (about 2000 employees). I do not have access to the SharePoint servers to install WSP’s, use STSADM, or even PowerShell.

I am in charge of all development for my Site Collection but getting a custom SharePoint web part or WSP solution into production takes weeks….and sometimes months. So, i began working with the Content Editor Web Parts (CEWP’s) to see if I can use the SharePoint Web Services and Javascript as a “Poor man’s” web part. My “Poor man’s” web parts are only CEWP’s which don’t have to go thru a special code review and approval process before being moved into the production SharePoint farm.

If you are under these same kind of restrictions, maybe you’d like to consider this approach as well. However, this isn’t the best approach in that things can ‘break’ easily if someone modifies your code in the CEWP’s.
 
(more…)

Connecting to the SharePoint ‘Lists.asmx’ web service without having to manually create a Web Service Reference

Up until recently I have been manually adding a Web Service Reference to my WinForms and WPF projects. I have been connecting to the SharePoint Web Services to pull data from my sites because of the limitations of not having access to the server to use the SharePoint Object Model. In an ideal situation, I would much rather use the SharePoint Object Model to access SharePoint data because I can do more with it and it’s not as complicated as using the SharePoint Web Services.

I’ve often wondered how I can reference the ‘lists.asmx’ web service without having to manually add a Web Service Reference in Visual Studio. Following this approach, you can call a web service (any web service) from your WinForms, WPF, Javascript, ASP.NET, etc. applications. (more…)

Using an XML “settings” file to store values for your SharePoint projects

I recently created a SharePoint timer job solution that relied on the data in a list as to what the function of the job was to do. The solution requirement was to have a timer job set to run at 8:00am every Thursday that would read SharePoint list data and create a customized email of that data for the week.

Since I work in an environment with multiple SharePoint farms, I had to rely on a ‘settings’ file that I could easily change without having to recompile and redeploy my WSP solutions. I will show you how to read the nodes and values of an XML file located in a SharePoint list that your SharePoint solutions can reference, thus eliminating the need to recompile your code for each SharePoint farm. Let’s get started…
(more…)

Adding a new Field Type

I thought I would make this entry about creating custom field types. I always forget how to do this since i’m not actively creating many types so I figured this is the best thing to do….as a reference.

Taken from the “Professional SharePoint 2007 Development” book (WROX), let’s do the following:

STEP 1: Creating a new FieldType

1. Create a new VS Class Library (Windows Project) in C# (you can use VB also)
2. Name the project “RYL_CustomFieldType” (or whatever you prefer)
3. Add a reference to “System.Web”
4. Add a reference to “Microsoft.SharePoint” (found in the %HIVE%\Bin on your SharePoint server)
5. Rename the “Class1.cs” file to “SocialSecurityNumber.cs”
6. Add a “public” modifier to the SocialSecurityNumber class if not already done.
7. Add “using” statements for both “Microsoft.SharePoint” and “System.Text.RegularExpressions”
8. Edit the class declaration to inherit from “SPFieldText”

(more…)