Showing posts with label Document Library. Show all posts
Showing posts with label Document Library. Show all posts

Tuesday, August 18, 2009

Compare Document Versions in Word 2007 with SharePoint

Sharepoint includes a feature to track a document's version history. You can see this history from Word 2007 by clicking on the Office Button and then selecting View Version History under Server.


Then you will get a window that shows all the different versions, their modified date, modifier, size and comments.


Highlight the version you want to compare and then click on the Compare button. Word will open the old version in a new window and then open another window that show both versions and their differences.


On the left you will see a list of the all the changes. In the center is the current document with the changes highlighted. On the right are both versions of the document. Now you have an easy and quick way to see the changes made in each version of the document.

Friday, February 20, 2009

Download a File Using the SharePoint Copy Web Service

Here is a code sample I put together to download a file from a Document Library using SharePoint's Copy web services.
// sharepoint is a web reference that points to http://sharepoint/_vti_bin/copy
sharepoint.Copy myCopyService = new sharepoint.Copy();
myCopyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

// URL to the file you want to downlaod
string copySource = "https://sharepoint/file.doc";

// Define the variables that will store the output from the web service call
sharepoint.FieldInformation myFieldInfo = new sharepoint.FieldInformation();
sharepoint.FieldInformation[] myFieldInfoArray = { myFieldInfo };
byte[] myByteArray;

// Call the web service
uint myGetUint = myCopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

// Convert into Base64 String
string base64String;
base64String = Convert.ToBase64String(myByteArray,0,myByteArray.Length);

// Convert to binary array
byte[] binaryData = Convert.FromBase64String(base64String);

// Create a temporary file to write the text of the form to
string tempFileName = Path.GetTempPath() + "\\" + myFieldInfoArray[0].Value;

// Write the file to temp folder
FileStream fs = new FileStream(tempFileName, FileMode.CreateNew, FileAccess.ReadWrite);
fs.Write(binaryData, 0, binaryData.Length);
fs.Close();

//Open file in default program
System.Diagnostics.Process.Start(tempFileName);

There is more information on the Copy web service here: http://msdn.microsoft.com/en-us/library/copy.aspx. Look under the Copy class and its GetItem method.