question

domix1996-2724 avatar image
0 Votes"
domix1996-2724 asked domix1996-2724 commented

Problem with sending file to SharePoint from remotely Windows server 2012 r2 by IIS8 (page.asmx)

I've problem with settings on remotely server (Windows 2012 r2) via remote desktop for sending files to SharePoint from my program.

First.. My program (program is a console application in .Net 4.6 and is on IIS8, for testing is WebService SOAP - program using web reference...) get data from database, next program generate file excel and write data in here. After our file is generated and ready, program read data user. (this is worked)

next when user is ready, program use WebClient (on C#), next is authorize and is trying upload by client.Upload but here connection is broke on server.. (in locally this is working, use IIS express - locally [Windows 10 Enterprise], on server - IIS8 [Windows 2012]).

and I have error in server: The underlying connection was closed: An unexpected error occurred on a send......System.....

when I debbugged with remotely debbuger on serwer I saw this:
106464-image.png

My script where is broke connection on the server (debugger is end here - client.UploadFile(CopyPath + @"/" + ExcelFile.Name, "PUT", ExcelFile.FullName);):

106444-image.png

I am asking for culture to be preserved and please not negatively me assessed as this code is from the previous owner. I do not have a contact with it and I need this code to automatically submit a report in the Scheduler. All the rest work except sending a file on the server to SharePoint. I have to keep the rules because such requirements in my job :/

Best regards Domino

Ps. If I did not give enough details, ask me go ahead. I will answer the fastest!


windows-server-iissharepoint-devwindows-server-2012
image.png (12.1 KiB)
image.png (51.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You issue is more related to share point. I will remove our network tag and add share point related tag. Thanks for your understanding.

1 Vote 1 ·

ok, thank you for advise..

0 Votes 0 ·

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered domix1996-2724 commented

Hi @domix1996-2724,

To upload files to SharePoint , we need to use SharePoint CSOM API to perform opearations: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code

Install the package Microsoft.SharePointOnline.CSOM: https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/

The NetworkCredential is not supported in SharePoint online. We use SharePointOnlineCredentials class to authenticate in SharePoint online site.

Below is my demo code for you to upload files to SharePoint:

         String name = "user@tenant.onmicrosoft.com";
         String password = "xxx";
         SecureString securePassword = new SecureString();
         foreach (char c in password.ToCharArray())
         {
             securePassword.AppendChar(c);
         }
         var credentials = new SharePointOnlineCredentials(name, securePassword);
         var siteUrl = "https://tenant.sharepoint.com/sites/yoursite";

         ClientContext ctx = new ClientContext(siteUrl);
         ctx.Credentials = credentials;
         var uploadFilePath = @"c\test.xlsx";
         var uploadFolderUrl = "https://tenant.sharepoint.com/sites/yoursite/library1/folder1";
         var fileCreationInfo = new FileCreationInformation
         {
             Content = System.IO.File.ReadAllBytes(uploadFilePath),
             Overwrite = true,
             Url = Path.GetFileName(uploadFilePath)
         };
         var targetFolder = ctx.Web.GetFolderByServerRelativeUrl(uploadFolderUrl);
         var uploadFile = targetFolder.Files.Add(fileCreationInfo);
         ctx.Load(uploadFile);
         ctx.ExecuteQuery();



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



If the response is helpful, please click "Accept Answer" and upvote it.


· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @domix1996-2724,

Is there anything update? Have you tried my solution?

0 Votes 0 ·

Yes, I tried your solution but this not work.. This problem is not from code, but from server...

----ERROR----:

 InnerEx: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

0 Votes 0 ·

Hi @domix1996-2724,
This could be that TLS1.2 is not enabled for your server. You could refer to this documentation for more: https://docs.microsoft.com/en-us/sharepoint/troubleshoot/administration/authentication-errors-tls12-support

0 Votes 0 ·
Show more comments