I've managed to succesfully create a document in a "settings" folder when a user makes and online enquiry to allow the client to view all enquiries.
Once thing i've notived that the name of the document just gets another (1), (2) etc on it...is there a better way to handle this?
Also I have no need to publish these files...is there a document type that i should create/use when storing data?
Code below..
'Now lets update umbraco so the client can view the enquiries Try
'Get the type you would like to use by its alias 'and the user who should be the creator of the document Dim dt As DocumentType = DocumentType.GetByAlias("tmGetInTouchResponse") Dim author As User = User.GetUser(0)
'create a document with a name, a type, an umbraco user, and the ID of the document's parent page. 'To create a document at the root of umbraco, use the id -1
Dim doc As Document = Document.MakeNew("Response", dt, author, 1480) 'Now enter the stuff we need to capture ' the value is saved in the database instantly! doc.getProperty("name").Value = txtFirstname.Text & " " & txtSurname.Text doc.getProperty("enquiryDate").Value = DateTime.Now doc.getProperty("contactTel").Value = txtTel.Text doc.getProperty("emailAddress").Value = txtEmail.Text doc.getProperty("enquiryDetails").Value = txtDetails.Text doc.getProperty("newslettersignup").Value = Newsletter
'after creating the document, prepare it for publishing
doc.Publish(author)
'Tell umbraco to publish the document umbraco.library.UpdateDocumentCache(doc.Id) Catch ex As Exception
panFeedbackSucess.Visible = False panFeedback.Visible = False litInfoErrorMessage.Text = "<p>Sorry there was an error we did not manage to capture your details to the database but they may have been sent by email.</p>"
Creating new documents from .Net control
I've managed to succesfully create a document in a "settings" folder when a user makes and online enquiry to allow the client to view all enquiries.
Once thing i've notived that the name of the document just gets another (1), (2) etc on it...is there a better way to handle this?
Also I have no need to publish these files...is there a document type that i should create/use when storing data?
Code below..
'Now lets update umbraco so the client can view the enquiries
Try
'Get the type you would like to use by its alias
'and the user who should be the creator of the document
Dim dt As DocumentType = DocumentType.GetByAlias("tmGetInTouchResponse")
Dim author As User = User.GetUser(0)
'create a document with a name, a type, an umbraco user, and the ID of the document's parent page.
'To create a document at the root of umbraco, use the id -1
Dim doc As Document = Document.MakeNew("Response", dt, author, 1480)
'Now enter the stuff we need to capture
' the value is saved in the database instantly!
doc.getProperty("name").Value = txtFirstname.Text & " " & txtSurname.Text
doc.getProperty("enquiryDate").Value = DateTime.Now
doc.getProperty("contactTel").Value = txtTel.Text
doc.getProperty("emailAddress").Value = txtEmail.Text
doc.getProperty("enquiryDetails").Value = txtDetails.Text
doc.getProperty("newslettersignup").Value = Newsletter
'after creating the document, prepare it for publishing
doc.Publish(author)
'Tell umbraco to publish the document
umbraco.library.UpdateDocumentCache(doc.Id)
Catch ex As Exception
panFeedbackSucess.Visible = False
panFeedback.Visible = False
litInfoErrorMessage.Text = "<p>Sorry there was an error we did not manage to capture your details to the database but they may have been sent by email.</p>"
End Try
1. If there is are 2 nodes with the same name created, umbraco will append a number to it. To get around this, you could change this line:
Document.MakeNew("Response", dt, author, 1480)
to something like
Document.MakeNew("Response" & txtFirstname.Text & " " & txtSurname.Text, dt, author, 1480)
This should give you some thing that will (most probably) be unique
2. If you don't need to publish the document, you could just call
doc.Save(author)
instead of
doc.Publish(author)
is working on a reply...