March 26, 2012 at 1:27 pm
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; }
March 26, 2012 at 1:32 pm
I am finding difficulty to execute this
Expand on what you mean by this please. What have you tried?
March 26, 2012 at 2:34 pm
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()
March 26, 2012 at 2:37 pm
Sorry the request method is DELETE instead of PUT.
request.Method = "DELETE";
March 26, 2012 at 2:39 pm
Have you stepped through the code in debug? This should help you identify the exact cause of the problem.
March 26, 2012 at 2:54 pm
I don't have C# installed in my machine. How do I do that..?
March 26, 2012 at 3:01 pm
But you have SSIS installed? Otherwise, how are you running this?
March 26, 2012 at 3:02 pm
Yes,SSIS installed in my machine.How do I debug from SSIS...?
March 26, 2012 at 3:05 pm
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.
March 26, 2012 at 4:15 pm
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.
March 26, 2012 at 4:40 pm
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.
Viewing 11 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy