【问题标题】:Using File manager with Sharepoint Online将文件管理器与 Sharepoint Online 一起使用
【发布时间】:2019-07-30 04:23:36
【问题描述】:

我正在尝试连接到 SharePoint Online 以浏览 SharePoint 上的文件夹并获取要导入到 sql 表中的图像文件。无法通过文件管理器访问它 - 路径显示为无效(如果我通过 SharePoint 浏览并输入我的 u/p - 路径可访问且有效)

我设置了一个代码询问用户密码(我自动获得的用户名),它似乎在线连接到 SharePoint,但是当我在浏览器中键入路径时 - 出现路径无效错误。

调用此代码传递 u/p(在幕后):

protected void ConnectShrpt_Click(object sender, EventArgs e)
    {
        String DocLibName = "Documents";
        If ((HiddenPassw.Value != "") && (HiddenUserEmail.Value !=""))
        {
        ClientContext clientContext = new ClientContext(FolderImage);              
                SharePointOnlineCredentials cred = new SharePointOnlineCredentials(HiddenUserEmail.Value, ConvertToSecureString(HiddenPassw.Value));
                clientContext.Credentials = cred;
                List list = clientContext.Web.Lists.GetByTitle(DocLibName);              
                clientContext.Load(list.RootFolder);
                clientContext.ExecuteQuery();  
            }
        }
​

我没有收到上述代码的任何错误消息。一旦我进入浏览器 - 使用 asp:FileUpload - 那就是我得到路径不存在的错误。如果我在同一个浏览器中手动进入同一个位置并输入 u/p - 那么我可以使用同一个 FileUpload 并浏览到该位置。我需要我的代码来自动连接到 SharePoint Online。 附言FolderImage 是 SharePoint 网站的网址。

更新!虽然我在开发人员环境中没有遇到任何错误,但在将其部署到 SharePoint Server IIS 后,我在上面附上的代码中遇到了错误..

[IOException: The handshake failed due to an unexpected packet format.]
   System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) +420
   System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +287
   System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) +357
   System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +203
   System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +827
   System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +357
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +20
   System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +77
   System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +1135
   System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +60
   System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +105
   System.Net.ConnectStream.WriteHeaders(Boolean async) +484

[WebException: The underlying connection was closed: An unexpected error occurred on a send.]
   System.Net.HttpWebRequest.GetResponse() +1518
   Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetIdcrlHeader(Uri url, Boolean alwaysThrowOnFailure, EventHandler`1 executingWebRequest) +1129
   Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetAuthenticationCookie(Uri url, String username, SecureString password, Boolean alwaysThrowOnFailure, EventHandler`1 executingWebRequest) +122
   Microsoft.SharePoint.Client.SharePointOnlineCredentials.GetAuthenticationCookie(Uri url, Boolean refresh, Boolean alwaysThrowOnFailure) +402
   Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request) +743
   Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream() +68
   Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate() +635
   Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() +104
   Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +1397
   AIM_Central._Default.ConnectShrpt_Click(Object sender, EventArgs e) in Default.aspx.cs:4139
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +129
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4949

【问题讨论】:

    标签: c# asp.net sharepoint-online


    【解决方案1】:

    检查“FolderImage”变量的数据。

    要传递 ClientContext 方法,您需要传递站点 url。

    string webUrl = "https://tenant-name.sharepoint.com/sites/test/";
    ClientContext clientContext  = new ClientContext(webUrl)
    

    【讨论】:

    • 调试代码并检查哪一行代码抛出了异常。
    • 我之前提到过,这段代码没有错误。它只是没有达到我的需要 - 没有解除与 SharePoint 上路径的连接。
    猜你喜欢
    • 2022-12-05
    • 2018-02-27
    • 2016-10-21
    • 2019-05-30
    • 2017-11-29
    • 2012-01-01
    • 2019-07-19
    • 2022-01-22
    • 2018-12-28
    相关资源
    最近更新 更多