The great thing is, you don’t just have to create a flat text file, you can also create other files that are also text based. Eg. CSV (comma separated values file that can be opened in Excel). XML files if you need to store some configuration data. Even InfoPath forms are XML files, so if you had the spare time and wanted to build up your own InfoPath form xml file, you could do that too. You could also create HTML files. You could be making a web service call and get XML back. You could then use XSLT to transform that into HTML and write the HTML to a file in a document library.
How do we accomplish this?
We use the Web Request action. A very powerful action which most people don’t use because it is a little intimidating. There are some obvious configuration options like GET and POST. There are also 2 options for the two versions of SOAP packets you can create to call web services or WCF services. Then there’s the “Other” option. This is the option we will use in this example because what we want to do is PUT file in a library.
For the URL, we put in the full url including the filename of the document we want to create.
In the body, we insert the text we want as the contents of that file.
That’s all there is to it. It doesn’t seem as scary now does it :).
I’ve created the following:
SharePoint List named “Create Text Files”.
SharePoint Library named “Text Files”.
The list will contain a choice field where you can pick if you want to create a Text file or a CSV file. The workflow will then take the title of the item, add the appropriate extension, create a dummy body of the type of file, and then create that file in the library.
As you can see, it’s a fairly straight forward workflow:
The Web Request is looks like this:
NOTE: If you create a list and library with the names above and then import this workflow into the list, you should have no problems running this test workflow, excepy you will need to update the credentials used in the Web Request action. I’ve configured it to use a Workflow Constant I have. So either create a constant with that name, or put in the appropriate credentials.