使用控制台应用程序将文件上载到Office 365 [英] Upload file to office 365 using console application

查看:101
本文介绍了使用控制台应用程序将文件上载到Office 365的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试使用控制台应用程序连接到Office 365,请找到我的cod ebelow。但我收到错误

无法联系指定网址的网站http://mysite-my.sharepoint.com



我尝试过:



Hi All,

I am trying to connect to Office 365 using console application , please find my cod ebelow. But i am getting error
Cannot contact site at the specified URL http://mysite-my.sharepoint.com

What I have tried:

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using Microsoft.SharePoint.Client;
using System.Net;
using Microsoft.SharePoint;

namespace OneDrive
{
    class Program
    {
        
        static void Main(string[] args)
        {
            GetSiteLists();
            Console.ReadLine();
        }
        
        class configuration
        {
            public static string o365SiteUrl = "http://mysite-my.sharepoint.com";
            public static string o365UserName = "username";
            public static string o365Password = "pwd";
            public static string o365Domain = "domail";
           
        }
        static ClientContext GetUserContext()
        {
            var o365password = new SecureString();
            foreach (char c in configuration.o365Password)
            {
                o365password.AppendChar(c);
            }
            // var o365Credentials = new SharePointOnlineCredentials(configuration.o365UserName, o365password);
           NetworkCredential o365Credentials = new NetworkCredential(configuration.o365UserName, o365password, configuration.o365Domain );
           

            ClientContext o365Context = new ClientContext(configuration.o365SiteUrl);
            System.Net.ServicePointManager.ServerCertificateValidationCallback =
        ((sender, certificate, chain, sslPolicyErrors) => true);

            o365Context.Credentials  = o365Credentials;
            return o365Context;
        }
        static void GetSiteLists()
        {
            var clientContext = GetUserContext();
            //clientContext.ExecutingWebRequest += clientContext_ExecutingWebRequest;
            var results = clientContext.LoadQuery(clientContext.Web.Lists.Include(List => List.Title, List => List.Id ));
            clientContext.ExecuteQuery();
            results.ToList().ForEach(x =>
            {
                Console.WriteLine(x.Title);
            });
            clientContext.Dispose();



        }
    

    }

推荐答案

Quote:

您可以使用我的网站来共享信息并与其他人联系以建立您的专业网络。本文介绍了一些关键功能,并提供了一些帮助您入门的步骤。

You can use your My Site to share information and connect with other people to build your professional network. This article describes some key features, and provides some steps to help you get started.





如上所述,您需要配置您的sharepoint站点。我强烈建议您阅读以下文章:

我的网站入门 - SharePoint [ ^ ]

在SharePoint Server 2013中配置我的网站 [ ^ ]


我尝试了很多事情但没有成功。所以我尝试使用Microsoft Graph,它工作正常。
I tried many things with no success. SO i have tried with Microsoft Graph and it worked fine.


这篇关于使用控制台应用程序将文件上载到Office 365的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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