0

I need to modify numerous packages to deliver a flat file to a SharePoint. I've found this routine online to do it via C# in a script task but I am getting a "remote server returned an error "(403) forbidden" error. Code is below. I am using visual studio 2008 and the package needs to run on SQL Server R2 server.

I've already set up the job to drop the file to a shortcut to the SharePoint that is linked in my one drive folder, but my server cant access that.. any work arounds? don't necessarily want to purchase a add on component for SSIS.

I've read online that the forbidden error is linked the security profile. I implemented the code online that I've seen that should fix the error but the step still fails

Anyone see any errors in my code that would cause the error is this strictly a permission issues?

I installed .NET framework 4.8 but with this old VS I am not available to validate that 4.8 is used.

            WebClient myWebClient;
        string DestinationURL;
        string LocalFileName = Dts.Variables["User::var_file"].Value.ToString(); 
        bool FireAgain = true;



        try
        {
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
            myWebClient = new WebClient();
            myWebClient.UseDefaultCredentials = true;
            DestinationURL = "https://share.sharepoint.com/sites/Data/Shared Documents/data/ Data.aspx";
            Console.WriteLine(LocalFileName);
            //myWebClient.UseDefaultCredentials = true;
            //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 error)
        {
           MessageBox.Show(error.Message);

        }
user3772443
  • 153
  • 1
  • 2
  • 9

0 Answers0