I have a document library with a DOCX template file. I want to create DOCX file in this library in a workflow but I did not succeed.
Before, I created a workflow in Sharepoint Designer to create a new item in the document library, but now I have to write this workflow in Visual Studio 2010 and it doesn't work.
Here is what I do in the workflow :
using (SPSite oSPsite = new SPSite("URL"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
var docLib = oSPWeb.Lists["gpReports"];
var fileName = "Title.docx";
Hashtable ht = new Hashtable();
ht.Add("Title", "Title");
ht.Add("ProjectYear", "Year");
ht.Add("ProjectDepartment", "Department");
docLib.RootFolder.Files.Add(fileName, new byte[] { }, ht, true);
oSPWeb.AllowUnsafeUpdates = false;
}
}
Every method of Add need a file or a byte array, but I want that the template of the document library is used.
Using the current method, it creates an empty file in the document library.
Is there a way to do that programmatically ?