Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using Listdata.svc to add or update list items on a remote sharepoint server. I need to know that if suppose I am using a tasks list and the items in the tasks list have attachment of file in them, then how to copy those attachments to the remote sharepoint server through "listdata.svc" service.

Thanks.

share|improve this question
    
is it possible to use the client object model for this ? –  Sebastien Stettler Feb 17 '12 at 15:37
    
I am asking ? as well... need answer to this –  RHM Feb 17 '12 at 15:40

1 Answer 1

up vote 1 down vote accepted

i haven't tried getting the binaries using the svc, but if you can get the URL of the attachment then, you can use the client object model to get the actual document.

http://msdn.microsoft.com/en-us/library/ee537083.aspx

File.OpenBinaryDirect(context,'server relitive url')

a demo getting the clientcontext object

public ClientContext getClientContext(string url, NetworkCredential credentials)
{
    ClientContext clientContext = new ClientContext(url);
    clientContext.Credentials = credentials;
    return clientContext;
}

EDIT :

To upload an atachment using Lists.asmx webservice You must first encapsulate the webservice this can be done using visual studio by adding a service refrence the url to the web service is

the webservice url is http://sharepoint/_vti_bin/Lists.asmx

once the webservice is ecapsulated you can call the addAtatchment method like this:

ListServiceExample.ServiceReference1.ListsSoapClient listWS = new ListServiceExample.ServiceReference1.ListsSoapClient();
NetworkCredential creds = new NetworkCredential("username","password");
creds.Domain = "domain";
listWS.ClientCredentials.Windows.ClientCredential = creds;
listWS.AddAttachment(ListName,ListItemID,fileName,Binary Array);

if you want to see what other methods you can call with this webservice just enter http://sharepoint/_vti_bin/Lists.asmx into your url remember to replace sharepoint with your instances host name.

also the rest of sharepoints webservices can be found in the %14hive%\ISAPI folder

Kind Regards

share|improve this answer
    
This is to get the attachment from a task item , but how to create an attachment to a taskitem . –  RHM Feb 20 '12 at 8:00
    
to add an attachment you will have to use the List asmx service, i will create a small code snippet for you tonight and add it to the above post –  Sebastien Stettler Feb 20 '12 at 9:09
    
Thanks will wait for that. –  RHM Feb 20 '12 at 10:54
    
sorry for the delay here is the answer to your question –  Sebastien Stettler Feb 21 '12 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.