SSIS Script task for Sharepoint

  • Iam trying to create a script task which deletes doc/xls from sharepoint which is older than 10 days. This is the code Iam trying to use it.I am finding difficulty to execute this. Thanks for your help.

    public void Main()

    {

    WebResponse response = null;

    try

    {

    string str = Dts.Variables["sharepointURL"].Value.ToString();

    WebRequest request = WebRequest.Create(str);

    request.Credentials = CredentialCache.DefaultCredentials;

    request.Method = "PUT";

    request.Timeout = Timeout.Infinite;

    response = request.GetResponse();

    }

    catch (Exception ex) { throw ex; }

    finally

    { if (response != null) { response.Close(); }

    }

    Dts.TaskResult = (int)ScriptResults.Success; }

  • I am finding difficulty to execute this

    Expand on what you mean by this please. What have you tried?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Iam getting this error

    Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Empty path name is not legal.

    at ST_20aed8fe3d0347a0b748f4bc14e21fe2.csproj.ScriptMain.Main()

    --- End of inner exception stack trace ---

    at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

    at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)

    at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

  • Sorry the request method is DELETE instead of PUT.

    request.Method = "DELETE";

  • Have you stepped through the code in debug? This should help you identify the exact cause of the problem.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I don't have C# installed in my machine. How do I do that..?

  • But you have SSIS installed? Otherwise, how are you running this?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Yes,SSIS installed in my machine.How do I debug from SSIS...?

  • Set a breakpoint in your code by clicking on one of the lines near the top and hitting F9. A red dot will appear in the margin.

    Save that and click the green run button.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • The build succeeds ,but Iam not able to find the problem.If you can point me why this error occurs then I can check that.

    Again I need a code to delete old files from SP.

  • What is specified in sharePointURL variable? I think you have some special characters, which have to escaped. Try to escape the URL, before creating the request. Try HttpServerUtility.UrlEncode method.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply