I have got custom content type
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Contract (PkbInfo.SP\Contract) (0x0101000bb17de4384349b2b6a6800bc8555513) -->
<ContentType ID="0x0101000bb17de4384349b2b6a6800bc8555513000cd70d4f20e241dcaf9cdd46ad9d963b"
Name="Podprogowa"
Group="PkbInfo.SP.ContentTypes"
Description="Umowa podprogowa"
Inherits="TRUE"
Version="0">
<FieldRefs>
</FieldRefs>
<Folder TargetName="_cts/ContractorTemplates" />
<DocumentTemplate TargetName="/_cts/ContractorTemplates/podprogowa.dotx" />
</ContentType>
</Elements>
I try do add file and set item properties
string fileName = "UDP-" + tbxDocNum.Text + ".doc";
SPContentType cct = SpWebManager.Contracts.ContentTypes[new SPContentTypeId(ddlTempleteTypes.SelectedValue)];
SPListItem itm = SpWebManager.Contracts.CreateDocument(_proContractsFld, cct, fileName);
SPFile f = itm.File;
itm = SpWebManager.Contracts.GetItemById(itm.ID);
itm["ContentType"] = cct;
itm["Invoice"] = new SPFieldLookupValue(_invoice.ID, _invoice.ID.ToString());
itm["ContractorPostCode"] = tbxPostcode.Text;
itm.Update();
where CreateDocument method is as below
public static SPListItem CreateDocument(this SPList list, SPFolder folder, SPContentType cct, string fileName, Hashtable ht)
{
string sTemplate = cct.DocumentTemplateUrl;
SPFile file = list.ParentWeb.GetFile(sTemplate);
byte[] binFile = file.OpenBinary();
string destFile = folder.ServerRelativeUrl + "/" + RemoveDisallowedCharsForFileName(fileName);
SPFile addedFile = folder.Files.Add(destFile, binFile,true);
SPListItem newItm = addedFile.ListItemAllFields;
return newItm;
}
The file is created. But when I open newly created document from library the "ContractorPostCode" is not set. On list item view (DispForm) there is value.
How to effective create new word document and init metadata fields from related file ListItem? The user should have "ContractorPostCode" filled in word adter first editing that file.
PS. I try http://sacarter.wordpress.com/2011/11/07/add-a-file-to-a-document-library-and-update-metadata-properties-in-a-single-method/ without luck