title: Upload file to Sharepoint 2013 using web service - Object reference not set to an instance of an object
body: <p>I'm trying to upload file to Sharepoint 2013 using web service copy.asmx</p>
  
  <p>I've created simple project with the following method:</p>
  
  <pre><code>public bool UploadFile(string file, string destination)
  {
  bool success = false;
  CopySoapClient client = new CopySoapClient();
  
  if (client.ClientCredentials != null)
  {
  client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("admin", "password", "domain");
  }
  
  try
  {
  client.Open();
  
  string filename = Path.GetFileName(file);
  string destinationUrl = destination +@"/"+ filename;
  string[] destinationUrls = { destination };
  
  FieldInformation i1 = new FieldInformation { DisplayName = "Title", InternalName = "Title", Type = FieldType.Text, Value = filename};
  FieldInformation[] info = { i1 };
  CopyResult[] result;
  byte[] data = File.ReadAllBytes(file);
  
  uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result);
  
  if (result != null &amp;&amp; result.Length &gt; 0 &amp;&amp; result[0].ErrorCode == 0)
  success = true;
  }
  finally
  {
  if (client.State == System.ServiceModel.CommunicationState.Faulted)
  client.Abort();
  
  if (client.State != System.ServiceModel.CommunicationState.Closed)
  client.Close();
  }
  
  return success;
  }
  </code></pre>
  
  <p>CopySoapClient is part Copy service reference </p>
  
  <pre><code>http://SPSITE/_vti_bin/copy.asmx
  </code></pre>
  
  <p>The method is called using following parameters:</p>
  
  <pre><code>UploadFile(@"C:\temp\test.txt", "http://SPSITE/sites/Connector/documents/test.txt");
  </code></pre>
  
  <p>The problem is, when program executes </p>
  
  <pre><code>uint ret = client.CopyIntoItems(file, destinationUrls, info, data, out result); 
  </code></pre>
  
  <p>the web service returns in result "Unknown error" with description "Object reference not set to an instance of an object."</p>
  
  <p>I really don't know what I'm missing. Can anyone help me out? </p>
  
  <p>Thank you.</p>
  
  <p>P.S. I've noticed in examples provided on the Internet that people are using a Copy class from copy.asmx. But I only have CopySoapClient class.</p>