Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

What I'm trying to do is upload a file with metadata without creating a new version using the client object model.

I already have this code:

  byte[] bytes = System.IO.File.ReadAllBytes(@"D:\inor.pdf");

  using (ClientContext context = new ClientContext(Properties.Settings.Default.SiteURL))
  {
    FileCreationInformation newFile = new FileCreationInformation()
    {
      Content = bytes,
      Url = string.Format("inor9.pdf", DateTime.Now.Ticks)
    };

    List certificateList = context.Web.Lists.GetByTitle("Certificaten");

    Microsoft.SharePoint.Client.File uploadFile = certificateList.RootFolder.Files.Add(newFile);

    uploadFile.ListItemAllFields.ParseAndSetFieldValue("CertificateNumber", "356");
    uploadFile.ListItemAllFields.Update();

    context.Load(uploadFile);
    context.ExecuteQuery(); 
  }

But the problem with this code is that 2 versions are created version 0.1 and 0.2. I don't want 2 versions because i have an itemreceiver on the itemadded that needs this certificatenumber. ItemAdded is now fired before the certificatenumber is added.

share|improve this question

3 Answers 3

It seems not to be possible to update item from client model without changing version, but you can use ItemUpdated instead of ItemAdded and check the version of file to be equal 0.2 or 2.0 depending on list version settings.

In server model there is a very useful method - SystemUpdate that updates without changing version, modified data and person who modified but client model seems to miss this functionaloty.

share|improve this answer
    
Pretty disappointing that there isn't something like systemupdate in the client model. I think i'm going to upload my files with a webservice. I already have the webservice, so i guess that will be the easiest way :) –  Marlou Nov 3 '11 at 13:45
    
Having a SystemUpdate method in the client model would be a pretty big security hole. –  Paul Lucas Jan 2 '12 at 22:09

what you could do is make the version property of you doc lib to false, while you are uploading. and turn it back on when you are done ?

share|improve this answer
    
In think that in that case my itemadded evenreceiver will still be fired before the metadata is added :( –  Marlou Nov 3 '11 at 13:41
up vote 0 down vote accepted

I've used the webservices that I've already created. In this webservice I use the server model and I'm able to use the systemupdate method

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.