I am creating a web api to upload the document in a specific folder in a sharepoint document library. I know how to it using csom in a console application.

The dlls which I am using in web api for sharepoint csom code are :- 1. Microsoft.SharePoint.Client.Portable 2. Microsoft.SharePoint.Client.Runtime.Portable 3. Microsoft.SharePoint.Client.Runtime.Windows

Dlls which is used for uploading documents in a console app are :-

  1. Microsoft.SharePoint.Client
  2. Microsoft.SharePoint.Client.Runtime

Csom code for console application :-

using (var filestream = new FileStream(filename, FileMode.Open))
                        var fileinfo = new FileInfo(filename);
                        var result = Path.GetFileName(filename);
                        var fileUrl = String.Format("{0}/{1}/", list.RootFolder.ServerRelativeUrl, caseno);
                        //Microsoft.SharePoint.Client.File newfile = list.RootFolder.Files.Add(fileUrl + result);
                        Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, fileUrl + result, filestream, true);

This is working fine in console application.

Same code if I am trying in with a web api it gives an error that "Microsoft.SharePoint.Client.File" doesn't contain a method name 'SaveBinaryDirect'.

Can anyone please help me? thanks in advance.

0 Answers