Hello,
I am facing an issue when i am tring to create a documet (.doc file) in sharepoint 2010 document library using template (.dotx) used by Document Content type.
I have created a template by adding some quickparts (site columns that are also in Document content type) with it and then uploaded it to Document Content type. now when i am trying to create a document through Document content type from document library its working as expected. when we change the values in quickparts by opening the document in edit mode and then save it back to document library , the changes get reflected in the fields in Document content type for that document. and also when I update the column values in document library for any document and save them and then when I open the same document in edit mode then those changes (done with field values from document library) get reflected as expected.
But I need to do the same (as describes above) through code. I have created a document using same template attached with Document content type and saved it in document library with same information in fields used as quickparts in template programmatically. and now when I open this (newly created) document in edit mode, the fields values don't get reflected in quikparts in document . also when I change the values in quickparts in the document and save them then that information don't update in fields in document library for that documet. I am using the below code for creating the document and saving it to Document content type with some information in fields (used as quickparts in template) in document library.
SPFolder folder = web.Folders[DocumentLibrary];
SPFile file = web.GetFile(web.Url + "/AventoDocumentLibrary/Forms/Document/template.doc");
SPFile destFile = folder.Files.Add("test.doc", file.OpenBinary(), true);
SPList docLib = Common.GetLibraryByUrl(DocumentLibrary); // will return Document Library
SPItem docListItem = docLib.GetItemById(destFile.ListItemAllFields.ID);
SPContentType docLibItemtype = docLib.ContentTypes["Document"];
docListItem["ContentTypeId"] = docLibItemtype.Id;
docListItem["Project"]="projectName";
// "Project" is a field in library with Document content type and used a quickpart in doument template
destFile.Properties.Add("Project", "projectName");
docListItem.Update();
destFile.Update();
the document has created (test.doc) and get saved to document library with value in "Project" successfully.
But Project value doesn't reflect in quickpart in document (test.doc).
Kindly suggest me where I am wrong in this senario.
Thanks in advance.