I am new to sharepoint so if I made something wrong please correct me.
I have a document library which takes appointments (a document, informations of the customer such as name, phone, etc.). Then I created a site page and web part which takes those informations form customer and send it to the document library. When I fill that form and save it, list takes parameters very well. After that, I created an approval sharepoint workflow for that library to approve documents by some users. Problem starts here: When I add items to document list manually(by pressing add item) workflow column item(name of workflow) is generated automatically and works well. But when I try to add by code workflow item is not generating.
public static void InsertIntoDocumentToLib( string name, int age,string path,SPContext context)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (var site = new SPSite(context.Site.ID))
{
using (var siteCollection = new SPSite(context.Site.Url)) // site.RootWeb
{
using (var currentWeb = siteCollection.OpenWeb(context.Web.ID))
{
SPList spList = currentWeb.Lists.TryGetList(DOCUMENT_LIB_NAME);
if (spList != null)
{
currentWeb.AllowUnsafeUpdates = true;
SPFolder myLibrary = currentWeb.Folders[DOCUMENT_LIB_NAME];
bool replaceExistingFiles = true;
string fileName = System.IO.Path.GetFileName(path);
FileStream fileStream = File.OpenRead(path);
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
spfile.Item[NAME_COLUMN] = name;
spfile.Item[AGE_COLUMN] = age;
spfile.Item.Update();
myLibrary.Update();
currentWeb.AllowUnsafeUpdates = false;
}
}
}
}
});
}