I am trying to load an attachment into a list:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication3.TestReference;
using System.IO;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string srcUrl = @"C:......comp_name.xlsx";
FileStream fStream = File.OpenRead(srcUrl);
string fileName = fStream.Name.Substring(3);
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
ServiceWebReference.Lists listService = new ServiceWebReference.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
string result = listService.AddAttachment("testList", "1", fileName, contents);
Console.WriteLine(result);
}
catch (System.Web.Services.Protocols.SoapException e)
{
Console.WriteLine(e.GetBaseException());
Console.WriteLine(e);
}
}
}
}
I get it Unhandled SOAP exception ....
Here is the complete exception I received:
System.Web.Services.Protocols.SoapException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at ConsoleApplication3.ServiceWebReference.Lists.AddAttachment(String listName, String listItemID, String fileName, Byte[] attachment)
in z:\Xxxxl\TestC\ConsoleApplication3\ConsoleApplication3\Web References\ServiceWebReference\Reference.cs:line 782
at ConsoleApplication3.Program.Main(String[] args)
in z:\Xxxxl\TestC\ConsoleApplication3\ConsoleApplication3\Program.cs:line 29
Press any key to continue . . .
I added the link correctly: http ..... /_vti_bin/lists.asmx
How to debug it? What is a SOAP exception in my case?
source
share