Hi
I am using this code in script task editor. I a getting error "Remote server returned an error: 403 forbidden"
public void Main()
{
// TODO: Add your code here
// var DestinationFolder = Dts.Variables["User::DestinationFolder"].Value.ToString();
//if (!Directory.Exists(DestinationFolder))
//{
// Directory.CreateDirectory(DestinationFolder);
//}
//Dts.TaskResult = (int)ScriptResults.Success;
WebClient myWebClient;
string DestinationURL;
string LocalFileName;
bool FireAgain = true;
try
{
myWebClient = new WebClient();
LocalFileName = @"C:\Foldername\Filename.csv";
DestinationURL = @"https://sharepointsitename/sites/TeamsFolder/Shared Documents/General/Folder Name/Filename.csv";
Console.WriteLine(LocalFileName);
myWebClient.Credentials = new NetworkCredential("userid", "password","domainname");
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);
}
}
Thanks
Nikz