Error while uploading file method in Client Object Model Sharepoint 2010

Posted by user1481570 on Stack Overflow See other posts from Stack Overflow or by user1481570
Published on 2012-06-30T01:34:22Z Indexed on 2012/06/30 9:16 UTC
Read the original article Hit count: 305

Filed under:
|

Error while uploading file method in Client Object Model + Sharepoint 2010. Once the file got uploaded. After that though the code compiles with no error

I get the error while executing

"{"Value does not fall within the expected range."}

{System.Collections.Generic.SynchronizedReadOnlyCollection}

I have a method which takes care of functionality to upload files

///////////////////////////////////////////////////////////////////////////////////////////

public void Upload_Click(string documentPath, byte[] documentStream)
{
    String sharePointSite = "http://cvgwinbasd003:28838/sites/test04";
    String documentLibraryUrl = sharePointSite +"/"+ documentPath.Replace('\\','/');

    ////////////////////////////////////////////////////////////////////
    //Get Document List
    List documentsList = clientContext.Web.Lists.GetByTitle("Doc1");

    var fileCreationInformation = new FileCreationInformation();

    //Assign to content byte[] i.e. documentStream
    fileCreationInformation.Content = documentStream;

    //Allow owerwrite of document
    fileCreationInformation.Overwrite = true;

    //Upload URL
    fileCreationInformation.Url = documentLibraryUrl;
    Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
    fileCreationInformation);             

    //uploadFile.ListItemAllFields.Update();
    clientContext.ExecuteQuery();
}

/////////////////////////////////////////////////////////////////////////////////////////////////

In the MVC 3.0 application in the controller I have defined the following method to invoke the upload method.

//////////////////////////////////////////////////////////////////////////////////////////////////

public ActionResult ProcessSubmit(IEnumerable<HttpPostedFileBase> attachments)
{
    System.IO.Stream uploadFileStream=null;
    byte[] uploadFileBytes;
    int fileLength=0;      

    foreach (HttpPostedFileBase fileUpload in attachments)
    {
        uploadFileStream = fileUpload.InputStream;
        fileLength=fileUpload.ContentLength;
    }

    uploadFileBytes= new byte[fileLength];
    uploadFileStream.Read(uploadFileBytes, 0, fileLength);

    using (DocManagementService.DocMgmtClient doc = new DocMgmtClient())
    {
        doc.Upload_Click("Doc1/Doc2/Doc2.1/", uploadFileBytes);
    }

    return RedirectToAction("SyncUploadResult");
}

//////////////////////////////////////////////////////////////////////////////////////////////////

Please help me to locate the error

© Stack Overflow or respective owner

Related posts about wcf

Related posts about sharepoint