15 December 2011

Sharepoint Upload File Error: ‘The remote server returned an error: (409) Conflict’

I’ve been using the following code to upload a file to a Sharepoint document library using the Client Object Model:

Code Snippet
  1. public string Save(string fileName, Stream fileStream)
  2.         {
  3.             string destinationUrl = String.Concat(serverRelativeLibraryUrl, "/", fileName);
  4.             ClientContext clientContext = new ClientContext(webUrl);
  5.             {
  6.                 Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, destinationUrl, fileStream, true);
  7.             }
  9.             return destinationUrl;
  10.         }

serverRelativeLibraryUrl = String.Concat(webRelativeUrl, libraryName);

But I kept getting the 409 Conflict Error:
ExceptionType: 'WebException'  ExceptionMessage: 'The remote server returned an error: (409) Conflict.'   StackTrace: ' 
at System.Net.HttpWebRequest.GetResponse()     
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()     
at Microsoft.SharePoint.Client.File.SaveBinary(ClientContext context, String serverRelativeUrl, Stream stream, String etag, Boolean overwriteIfExists, SaveBinaryCheckMode checkMode)     
at Microsoft.SharePoint.Client.File.SaveBinaryDirect(ClientContext context, String serverRelativeUrl, Stream stream, Boolean overwriteIfExists)     

After struggling for a while, I figured out that the problem was the library name. It contained a dash on it, like “My-LibraryName”. When I renamed it without the dash it started working.

The error in the code is how I built the URL. I was using the library name to build the library URL, but it seems that Sharepoint doesn’t like some characters in the URL, so when you create a library called “My-LibraryName”, the URL is actually http://<server>/MyLibraryName, without the dash.

Technorati Tags:

21 September 2011

Sharepoint @ Buenos Aires Codecamp 2011

BA Codecamp 2011 is coming soon and Tellago is going to be part of it! More than 10 architects from our team will be presenting the most innovative technology sessions on next October 15. I’m very happy to be speaking at this event! Along with my colleague Mariano Escurra, we will be presenting Best Practices using Javascript and JQuery in Sharepoint 2010. Bellow is the abstract. Register!!

Mejores prácticas utilizando Javascript y JQuery en SharePoint 2010
El uso de Javascript es una parte importante en la construcción de cualquier sitio web interactivo, siendo JQuery una de las bibliotecas Javascript más utilizadas. Al crear este tipo de sitios sobre SharePoint 2010, los desarrolladores pueden combinar el uso esta biblioteca con el modelo de objetos cliente Javascript (ECMAScript) mejorando notablemente la experiencia del usuario final.
Durante esta charla abordaremos los aspectos más importantes del modelo de objetos cliente ECMAScript de SharePoint 2010 y su integración con JQuery siguiendo las mejores prácticas.

Banner CodeCamp 587x293

17 June 2011

Fixing Sharepoint’s “Cannot connect to the configuration database” error

I have Sharepoint Server 2010 installed in my development environment. It happened a couple of times that the computer hangs and the Sharepoint Configuration dabatase remains in a corrupted state. When I try to access the Sharepoint local site from the browser it gives the following error:

Cannot connect to the configuration database.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot connect to the configuration database.

So, how did I fix it?

I first used this addselftosqlsysadmin.cmd script to add my account to the SQLServer sysadmin group.

Then performed the following commands from SQL Server Management Studio:

select state_desc from master.sys.databases where name = 'SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45'

The result was: SUSPECT, confirming we had a problem.

Then run:

ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET EMERGENCY;


ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET SINGLE_USER;


DBCC CHECKDB ([SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45] , REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;


ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]  SET MULTI_USER;


That’s it! I run the state_desc command again and this time it says: ONLINE


01 April 2011

Azure Bootcamp @MS Argentina

I participated yesterday in the Azure Bootcamp that took place at Microsoft Argentina. Along with Vanesa Guccione, my colleague at Lagash, we talked about advanced roles. The contents of the presentation included the new features of the platform, such as full IIS mode, startup tasks, remote desktop plugin and local storage. We also talked about input and internal endpoints and inter-role communication, showing some demo code as well. You can download the material from here.