peterm-technologyevaluation
-
4/1/2013 4:20:02 PM
attachment to a new culture version of this document
There is something what I am missing about creating file attachment for a new culture. Basically I am creating a document with file attachment in several languages.
It clearly works if I do it manually in CMS Desk: Create a document in English attach English file. Create culture version of it in Spanish attach Spanish file.
Programmatically if I try to repeat the same sequence if I create Spanish attachment after English I overwrite English attachment and I end up with Spanish attachment for English and for Spanish version.
I have this InsertAsNewCultureVersion ,but there is no "InsertCultureVersionAttachment".
For example if I have English Spanish and Chinese : First I create English then Spanish then Chinese. I create 3 cultures with 3 “cultural” attachments , but because Chinese culture is the last in my loop it overwrites the attachments in English and Spanish.
Here some basic code sample:
// Create a new document
string defaultDocumentPath = "/Content-Library/"; string defaultSite = CMSContext.CurrentSiteName; string defaultCulture = "en-us";
UserInfo ui = UserInfoProvider.GetUserInfo("administrator"); TreeProvider tree = new TreeProvider(ui); // Get parent node TreeNode parentNode = tree.SelectSingleNode(defaultSite, defaultDocumentPath, defaultCulture);
TreeNode node = TreeNode.New("Custom.MyDocument", tree);
// Set the document properties node.DocumentName = "My English Document"; node.DocumentCulture = defaultCulture;
// attache file to english document AttachmentInfo newAttachment = null; // Path to the file to be inserted. This example uses an explicitly defined file path. However, you can use an object of the HttpPostedFile type (uploaded via an upload control). string postedFile = Server.MapPath("/samples/English.xls"); newAttachment = DocumentHelper.AddAttachment(node, "Sample", postedFile, tree);
node.Update();
...
// create spanish version node.DocumentName = "Mi documento españolas"; node.InsertAsNewCultureVersion("es-ES"); newAttachment = null; postedFile = Server.MapPath("/samples/spanish.xls"); newAttachment = DocumentHelper.AddAttachment(node, "Sample", postedFile, tree); node.Update();
|