Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is to access a Excel file located in a SharePoint Team site using C#. I can upload and download files directly from the site, I have given permission for that. But the site is maintained by some other group, which no service is exposed. Is there any approach to access the file using C#.
Posted
Comments
Rajat_RJT 2-Mar-15 5:27am    
are you asking for Sharepoint version 2010 or 2013?
jagadesh437 2-Mar-15 6:59am    
I am unaware of the version they are using. I am having only access to the SP site. Now i want to access the uploaded file from my C# code.

1 solution

Try this code -
I added a web reference to
http://servername/_vti_bin/copy.asmx
where server should be replaced by sharepoint server name
Suppose, I give it a name CopyReference

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;



namespace Asmx
{
    class Program
    {
        static void Main(string[] args)
        {

            CopyReference.Copy copyService = new CopyReference.Copy();
            copyService.Url = @"http://server/_vti_bin/copy.asmx"; // change    server to your sharepoint server
            copyService.Credentials = new NetworkCredential("username", "password");


            string copySource = @"http://server/Shared Documents/document1.docx"; //location of the file on server
            Console.WriteLine("Here");

            CopyReference.FieldInformation myFieldInfo = new  CopyReference.FieldInformation();
            CopyReference.FieldInformation[] myFieldInfoArray = { myFieldInfo };
            byte[] myByteArray;
            Console.WriteLine("Here");

            copyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);
            Console.WriteLine(myByteArray.ToString());
            Console.ReadKey();


        }
     }
}
 
Share this answer
 
Comments
jagadesh437 3-Mar-15 0:21am    
They don't had the service exposed. Is there any other way ?
Rajat_RJT 3-Mar-15 2:30am    
If lists.asmx service is exposed, then you can try following link-
http://blogs.msdn.com/b/sowmyancs/archive/2007/09/15/how-to-download-files-from-a-sharepoint-document-library-remotely-via-lists-asmx-webservice-sps-2003-moss-2007.aspx
jagadesh437 3-Mar-15 4:38am    
Any idea how to know whether service is exposed or not ?
Rajat_RJT 3-Mar-15 6:03am    
yeah, just hit the url on browser http://servername/_vti_bin/Lists.asmx, if it works fine, your service is exposed.
jagadesh437 3-Mar-15 7:10am    
Yes that worked for me, but I don't see any methods which are useful. Looks like it created default request and response methods. Any clue ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900