ramon.almarza-emtmadrid
-
2/2/2010 3:27:07 AM
Attachment file
Good morning,
We’re developing a web site for the municipal transport company in Madrid and we have a problem.
We´re triying to attach files to a node. The code that we are using is here:
private static void CrearFichero(string nombreEnlace, string enlace, string nombreFichero, CMS.TreeEngine.TreeNode nodoPadre, TreeProvider tree,String certificado) { CMS.TreeEngine.TreeNode node=new CMS.TreeEngine.TreeNode("CMS.File", tree); try { // Create new document //string fileName = Path.GetFileNameWithoutExtension(FileUpload.FileName); node.DocumentCulture = CMSContext.PreferredCultureCode; node.DocumentName = nombreFichero;
// Load default values CMS.FormEngine.FormHelper.LoadDefaultValues(node);
node.SetValue("FileDescription", ""); node.SetValue("FileName", nombreFichero); node.SetValue("textoEnlace", nombreEnlace); node.SetValue("UrlCertificadoFandango", certificado);
// Set default template ID //if (templateId > 0) //{ // node.DocumentPageTemplateID = templateId; //} //else //{ // Get the class CMS.SettingsProvider.DataClassInfo ci = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("CMS.File"); if (ci == null) { throw new Exception("[Content/Edit.aspx]: Class 'CMS.File' not found."); } node.DocumentPageTemplateID = ci.ClassDefaultPageTemplateID; //}
// Insert the document DocumentHelper.InsertDocument(node, nodoPadre.NodeID, tree); //Fichero AttachmentManager am = new AttachmentManager(tree.Connection);
// Create the attachment Guid attachmentGuid = Guid.NewGuid();
AttachmentInfo ai = new AttachmentInfo("c:\\temp\\" + nombreFichero, node.DocumentID, attachmentGuid, tree.Connection);
am.SetAttachmentInfo(ai);
// Set the attachment reference node.SetValue("FileAttachment", attachmentGuid); node.Update(); DocumentHelper.UpdateDocument(node, tree); // Add the file //DocumentHelper.AddAttachment(node, "FileAttachment", FileUpload.PostedFile, tree);
// Create default SKU if configured if (ModuleEntry.CheckModuleLicense(ModuleEntry.ECOMMERCE, UrlHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert)) { node.CreateDefaultSKU(); }
WorkflowManager wm = new WorkflowManager(tree); // Approve until the step is publish WorkflowStepInfo currentStep = wm.GetStepInfo(node); while ((currentStep != null) && (currentStep.StepName.ToLower() != "published")) { currentStep = wm.MoveToNextStep(node, ""); }
} catch (Exception ex) { // Delete the document if something failed if ((node != null) && (node.DocumentID > 0)) { DocumentHelper.DeleteDocument(node, tree, false, true, true); } //lblError.Text = ResHelper.GetString("NewFile.Failed") + ": " + ex.Message; } }
But this isn´t working well, because the file not attach to the node. The element CMS.File is created, but the attach file is not included in the property FileAttachment. Is this code correct?? What’s the problem??
Thanks in advance.
|