I'm trying to connect to SharePoint Online to browse the folder on SharePoint and get the image file to import into sql table. Unable to get to it through File Manager - the path shows as invalid (if I browse through SharePoint and enter my u/p - path is accessible and valid)
I had setup a code asking for user's password (username I get automatically) and it seems to connect to SharePoint online, however when I type the path in the browser - get invalid path error.
Calling this code to pass u/p (behind the scenes):
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();
}
}
I don't get any error messages for the code above. Once I get to the browser - using asp:FileUpload - that's when I get the error that path doesn't exist. If I manually go in the same browser to the same location and enter u/p - then I can use the same FileUpload and browse to that location. I need my code to connect to the SharePoint Online automatically. P.S. FolderImage is the SharePoint site' url.
Update! While I got no errors in the developer environment, once I deployed it to the SharePoint Server IIS - getting an error on the code that I enclosed above..
[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