Skip to main content
deleted 18 characters in body
Source Link
List docs = context.Web.Lists.GetByTitle("test"); 
                var localFile = new FileCreationInformation(); 
                localFile.Content = ReadFully(_openFileDialog.File.OpenRead(),
_openFileDialog.File.Length);
                // localFile.Overwrite = true;

                string FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(_openFileDialog.File.Name);

                string FileExtension = System.IO.Path.GetExtension(_openFileDialog.File.Name);

                
                    localFile.Overwrite = true; 
                    localFile.Url = System.IO.Path.GetFileName(_openFileDialog.File.Name);
               

                file = docs.RootFolder.Files.Add(localFile);
                context.Load(file);
                AgenaDocs =text= file.ListItemAllFields;
                AgenaDocs["Title"]text["Title"] = file.Name;
               
                AgenaDocstext.Update();
                context.Load(file.ListItemAllFields);
                context.ExecuteQueryAsync(sucess, failed);
List docs = context.Web.Lists.GetByTitle("test"); 
                var localFile = new FileCreationInformation(); 
                localFile.Content = ReadFully(_openFileDialog.File.OpenRead(),
_openFileDialog.File.Length);
                // localFile.Overwrite = true;

                string FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(_openFileDialog.File.Name);

                string FileExtension = System.IO.Path.GetExtension(_openFileDialog.File.Name);

                
                    localFile.Overwrite = true; 
                    localFile.Url = System.IO.Path.GetFileName(_openFileDialog.File.Name);
               

                file = docs.RootFolder.Files.Add(localFile);
                context.Load(file);
                AgenaDocs = file.ListItemAllFields;
                AgenaDocs["Title"] = file.Name;
               
                AgenaDocs.Update();
                context.Load(file.ListItemAllFields);
                context.ExecuteQueryAsync(sucess, failed);
List docs = context.Web.Lists.GetByTitle("test"); 
                var localFile = new FileCreationInformation(); 
                localFile.Content = ReadFully(_openFileDialog.File.OpenRead(),
_openFileDialog.File.Length);
                // localFile.Overwrite = true;

                string FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(_openFileDialog.File.Name);

                string FileExtension = System.IO.Path.GetExtension(_openFileDialog.File.Name);

                
                    localFile.Overwrite = true; 
                    localFile.Url = System.IO.Path.GetFileName(_openFileDialog.File.Name);
               

                file = docs.RootFolder.Files.Add(localFile);
                context.Load(file);
                text= file.ListItemAllFields;
                text["Title"] = file.Name;
               
                text.Update();
                context.Load(file.ListItemAllFields);
                context.ExecuteQueryAsync(sucess, failed);
Source Link

This is helper method to return the bytes form the stream. Please let me know if you face any issue with this code.

I am using the same code in SilverLight Application.

public static byte[] ReadFully(Stream input, long fileSize)
        {

            //long fileSize = input.Length;

            byte[] buffer = new byte[fileSize];

            //   byte[] newArray = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }

Use var localFile = new FileCreationInformation() for saving a file using client Object model.

List docs = context.Web.Lists.GetByTitle("test"); 
                var localFile = new FileCreationInformation(); 
                localFile.Content = ReadFully(_openFileDialog.File.OpenRead(),
_openFileDialog.File.Length);
                // localFile.Overwrite = true;

                string FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(_openFileDialog.File.Name);

                string FileExtension = System.IO.Path.GetExtension(_openFileDialog.File.Name);

                
                    localFile.Overwrite = true; 
                    localFile.Url = System.IO.Path.GetFileName(_openFileDialog.File.Name);
               

                file = docs.RootFolder.Files.Add(localFile);
                context.Load(file);
                AgenaDocs = file.ListItemAllFields;
                AgenaDocs["Title"] = file.Name;
               
                AgenaDocs.Update();
                context.Load(file.ListItemAllFields);
                context.ExecuteQueryAsync(sucess, failed);