Reputation: 25429
As a temporary stopgap until all the designers are in place we are currently hand-cranking a whole bunch of xml configuration files at work. One of the issues with this is file-versioning because people forget to update version numbers when updating the files (which is to be expected as humans generally suck at perfection).
Therefore I figure that as we store the files in Sharepoint I should be able to write a script to pull the files down from Sharepoint, get the version number and automatically enter/update the version number from Sharepoint into the file. This means when someone wants the "latest" files they can run the script and get the latest files with the version numbers correct (there is slightly more to it than this so the reason for using the script isn't just the benefit of auto-versioning).
Does anyone know how to get the files + version numbers from Sharepoint?
Upvotes: 1
Views: 1971
Reputation: 13432
I am assuming you are talking about documents in a list or a library, not source files in the 12 hive. If so, each library has built-in versioning. You can access it by clicking on the Form Library Settings available from each library (with appropriate admin privs, of course). From there, select Versioning Settings, and choose a setup that works for your process.
As for getting the version number in code, if you pull a SPListItem
from the collection, there is a SPListItemVersionCollection
named Versions attached to each item.
Upvotes: 1
Reputation: 13432
There is a way to do it thru web services, but I have done more with implementing custom event handlers. Here is a bit of code that will do what you want. Keep in mind, you can only execute this from the server, so you may want to wrap this up in a web service to allow access from your embedded devices. Also, you will need to reference the Microsoft.SharePoint.dll in this code.
using (SPSite site = new SPSite("http://yoursitename/subsite"))
{
using (SPWeb web = site.OpenWeb())
{
SPListItemCollection list = web.Lists["MyDocumentLibrary"].GetItems(new SPQuery());
foreach(SPListItem itm in list) {
Stream inStream = itm.File.OpenBinaryStream();
XmlTextReader reader = new XmlTextReader(inStream);
XmlDocument xd = new XmlDocument();
xd.Load(reader);
//from here you can read whatever XML node that contains your version info
reader.Close();
inStream.Close();
}
}
}
The using() statements are to ensure that you do not create a memory leak, as the SPSite and SPWeb are unmanaged objects.
Edit: If the version number has been promoted to a library field, you can access it by the following within the for loop above:
itm["FieldName"]
Upvotes: 1