从SharePoint站点访问文件 [英] Access a file from a SharePoint site

查看:76
本文介绍了从SharePoint站点访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是使用C#访问位于SharePoint Team站点中的Excel文件。我可以直接从网站上传和下载文件,我已经获得了许可。但该网站由其他一些组维护,没有任何服务暴露。是否有任何方法可以使用C#访问该文件。

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#.

推荐答案

试用此代码 -

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();


        }
     }
}


这篇关于从SharePoint站点访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆