ScottN

Okay, I have recently been working a lot with SharePoint Workflows and have encountered quite a road-block with my current one. I am trying to make a tiny piece of code that copies the file a workflow is used on from a document library on one SharePoint site, to a document library on a different SharePoint site. The following line is what causes the problem:

workflowProperties.Item.File.CopyTo("WebPartDebug/DebugFiles/" + workflowProperties.Item.Name, true);

The second site is a subsite of my main site, so that is why the URL I'm sending CopyTo does not include the full http://whatever. Now, if I were to use:

workflowProperties.Item.File.CopyTo("Metadata Testing2/" + workflowProperties.Item.Name, true);

...where Metadata Testing2 is another document library on the same site, the CopyTo will work flawlessly.

I set up a try and catch block so if any exceptions are thrown, I put the Exception message into a sufficient log. The error that is ALWAYS returned when trying to access a folder outside of my parent site is "Folder [foldername] does not exist!" ...where [foldername] will be the last folder in the URL.

Now... obviously I am missing something, but after spending hours trying to puzzle out what is wrong, I have come up with nothing. Is there a way to copy and paste files from a document library on one SPSite, to a document library on a different SPSite If this is only possible if they're both on the same host that is still fine.

Thank you in advance.




Re: SharePoint - Workflow Copying a file from one SPSite to another?

Simon Doy

What happens if you substitute an html character for space (%20) for the space in "Metadata Testing2"

Regards

Simon






Re: SharePoint - Workflow Copying a file from one SPSite to another?

ScottN

The sample command involving "Metadata Testing2" is the actual line that works. Metadata Testing2 is part of the local site and thus I was just giving it as an example of a similar CopyTo call that does, in fact work. It doesn't appear to make a difference whether or not the special characters such as %20 are used or not.

My problem is simply the copying of a file from one document library on one site, to another document library on a different site. For some reason trying to access a library outside the local site causes CopyTo to not realize the library exists.




Re: SharePoint - Workflow Copying a file from one SPSite to another?

Simon Doy

Are you crossing Site Collection boundaries






Re: SharePoint - Workflow Copying a file from one SPSite to another?

ScottN

I would say no. The way it's structured is...

(Parent Site) -> (Sub-Site of Parent)
-StartingLibrary -DestinationLibrary

So basically... the file is attempting to be copied from the main parent site, to a sub-site of that parent.

I can't say I'm all that impressed with Workflows so far... They have been nothing but trouble, and are needlessly difficult to debug. It seems all they're good for so far is failing to run due to all the limitations around them.




Re: SharePoint - Workflow Copying a file from one SPSite to another?

Simon Doy

Yeah they do seem a little bit troublesome. I would recommend add a tracelistener to your web.config and then at least your debug comments can be traced.

I have some code which does what you ask. I will post it when I get to work tomorrow.

Regards

Simon






Re: SharePoint - Workflow Copying a file from one SPSite to another?

KevinHou

Scott,

I've gotten it work copying from one site to another. My CopyTo syntax is slightly different, I don't know if it will make any difference but just thought I'd throw it out there anyway. I use this syntax:

workflowProperties.Item.CopyTo("my fully qualified target URL here" + workflowProperties.Item.File.Name.ToString());

That's it, hope it helps. One other note, I just had a post answered about my other problem: if you copy an MS Office file from one doc lib to another, all the metadata gets written inside the file (Word, Excel, etc) and then if matching metadata columns exist in the target doc lib, it will place the values into the metadata columns for you. If however, you attempt to copy a non-Office file (.txt, pdf, etc), then there are two things to note: (1) If the source metadata and target metadata columns are identical datatypes, the metadata gets copied to the target correctly. (2) If the target metadata columns are of a different datatype than the source, then you will need to perform the copy of this metadata explicitly within your workflow. For example I have a 'choice' datatype in my source doc lib, but it is a 'single line text' datatype on the target doc lib (we just need the one value on the target, don't need to repopulate all the choices there). So here the datatypes differ for the same metadata column name. In this case the metadata is not copied for you, I wrote code to do the copy after a successful completion of the CopyTo function.

Good luck, I feel your pain and frustrations with workflows,

Kevin