using Microsoft.SharePoint.Client;
....
using(var ctx = new ClientContext("http://yoursharepoint/web_containing_library/"))
{
var lib = ctx.Web.Lists.GetByTitle("Title of your library");
var files = lib.RootFolder.Files;
ctx.Load(files);
ctx.ExecuteQuery();
foreach(var file in files)
{
if(file.Name.ToLower().EndsWith(".doc")
{
string newFilename = file.Name + "x"; //dirty hack :)
file.MoveTo(newFilename, MoveOperations.Overwrite);
ctx.ExecuteQuery();
//not sure if you need this, try without first
ctx.Load(file);
ctx.ExecuteQuery();
//convert DOC content to DOCX
var fi = File.OpenBinaryDirect(ctx, file.ServerRelativeUrl);
//get content using fi.Stream and convert it
//save it
File.SaveBinaryDirect(ctx, file.ServerRelativeUrl, streamWithDOCX, true);
}
}
}
Monday, 19 December 2011
Upgrade .doc to .docx in-place in a doc library
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment