How upload a file from my pc in sharepoint online

Donatella Candelo 20 Reputation points
2024-03-01T11:15:38.9466667+00:00

Hi, I create a ssis that produce a file xls test.xlsx, saved in a local directory of my pc. Then I would like to copy this file in a sharepoint online es. https://xxxxmy.sharepoint.com/:f:/r/personal/xxxxxxx/Documents/pinco.pallino?csf=1&web=1&e=LP7Zjw . Can you help me?
I used a task script and I wrote this code:

#region Namespaces

using System;

using System.Data;

using Microsoft.SqlServer.Dts.Runtime;

using Microsoft.SqlServer.Dts.Tasks.ScriptTask;

using System.Windows.Forms;

using System.Net;

using System.IO;

#endregion

namespace ST_08385185b50b4a0ba9e0b41b753ff88e

{

/// <summary>

/// ScriptMain is the entry point class of the script.  Do not change the name, attributes,

/// or parent of this class.

/// </summary>

[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

{

  	   public void Main()

	{

        // TODO: Add your code here

        WebClient myWebClient;

        string LocalFileName;

        string DestinationURL;

        bool FireAgain = true;

        try

        {

            ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);

            myWebClient = new WebClient();

            //myWebClient.UseDefaultCredentials = true;

            LocalFileName = "C:\\xxxxxx\\test.xlsx";

            // Destination file name with year and month appended ( SomeFile_04-23-2014.csv )

            DestinationURL = "https://xxxxmy.sharepoint.com/:f:/r/personal/xxxxxxx/Documents/pinco.pallino?csf=1&web=1&e=LP7Zjw/test.xlsx"

            Console.WriteLine(LocalFileName);

            myWebClient.Credentials = new NetworkCredential("xxxxx", "xxxxxx", "xxxx");//(“username”, “password”,”domain”);

            myWebClient.Credentials = CredentialCache.DefaultNetworkCredentials;

            Dts.Events.FireInformation(0, String.Empty, String.Format("Uploading {0} to {1}", LocalFileName, DestinationURL), String.Empty, 0, ref FireAgain);

            // upload the file

            myWebClient.UploadFile(DestinationURL,"PUT", LocalFileName);

        }

        catch (Exception ex)

        {

            // Catch and handle error

            Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0);

            //MessageBox.Show(DestinationURL);

            MessageBox.Show(ex.Message);

        }

        Dts.TaskResult = (int)ScriptResults.Success;

	}

    #region ScriptResults declaration

   enum ScriptResults

    {

        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,

        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

    };

    #endregion

}

}

When I run ssis it gives me this error: remote server error (403) Forbidden.

Thanks,

Donatella

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,836 questions
SQL Server Migration Assistant
SQL Server Migration Assistant
A Microsoft tool designed to automate database migration to SQL Server from Access, DB2, MySQL, Oracle, and SAP ASE.
538 questions
0 comments No comments
{count} votes

Accepted answer
  1. way0utwest 81 Reputation points MVP
    2024-03-01T15:45:45.04+00:00

    How are you running the SSIS package? It's likely this is running under a service account in SQL Server, which may not have rights to access sharepoint.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Donatella Candelo 20 Reputation points
    2024-03-14T09:20:01.5533333+00:00

    Thanks way0utwest, It's probable.


  2. Donatella Candelo 20 Reputation points
    2024-07-17T09:05:50.11+00:00

    Hi Kumar, no, I was not able to solve the problem, temporarily abandoned.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.