lunes, 23 de enero de 2012

Subir archivos grandes a SharePoint 2010 con Client Object

When you use SharePoint Client OM to upload files to SharePoint 2010 Document Library, uploading of files larger than 3 MB fail with the following error:

The remote server returned an error: (400) Bad Request.

Stack trace:
System.Net.WebException was unhandled
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
      at System.Net.HttpWebRequest.GetResponse()
      at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
      at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
      at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
      at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
      at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
      at SPClientOMConsoleApp.Program.Main(String[] args) in C:\SPClientOMConsoleApp\SPClientOMConsoleApp\Program.cs:line 32
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Sample program used to upload file using SharePoint 2010 Client OM:

ClientContext clientContext = newClientContext("http://server:10000/sites/testSite");
Web web = clientContext.Web;
clientContext.Load(web);
List docLib = web.Lists.GetByTitle("doclib");
clientContext.Load(docLib);
clientContext.ExecuteQuery();
byte[] bFile = System.IO.File.ReadAllBytes(@"C:\largeFile.docx");
FileCreationInformation file = new FileCreationInformation();
file.Content = bFile;
file.Url = "http://server:10000/sites/testSite/doclib/" +"test.docx";
Microsoft.SharePoint.Client.File newFile = docLib.RootFolder.Files.Add(file);
clientContext.Load(newFile);
clientContext.ExecuteQuery();

Fuentes:

http://support.microsoft.com/kb/2529243

http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

No hay comentarios:

Publicar un comentario