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.
How upload a file from my pc in sharepoint online
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
2 additional answers
Sort by: Most helpful
-
Donatella Candelo 20 Reputation points
2024-03-14T09:20:01.5533333+00:00 Thanks way0utwest, It's probable.
-
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.