I've just made a usercontrol which is placed on the dashboard in umbraco to create a new member and then create a node assigned to this member. All is working as expected, but when I refresh the content tree, the created note shows up twice (with the same id) I've tried to republish entire site and reload all nodes, but nothing works.
Has anyone ever found a solution to this problem? I have done a search both here on our.umbraco.org, google and stackoverflow.com but I haven't found a way to counter it yet :(
Also, as a side-question: what I don't like about this method is, that I have to hardcode the id of the parent node (1112) and the login and loginerror (1079, 1083) pages. Is there any other, more elegant way of doing this?
Most of the time when I create a user control that needs parameters like the root node, or login pages, etc. I'd create a config file for it and put the configuration details there. Read them out into static variables when the user control is created so you don't have to unecessarily do more disk read operations.
Regarding the duplicate node issue: what version of Umbraco are you using? I'm doing essentially the same thing when creating the document, but not seeing the duplicate node issue. Mind you, I'm not trying to protect the document. My code looks like this:
var docType = DocumentType.GetByAlias(Configuration.CategoryDocumentType);
Hi Robert, thanks for tuning in! :) greatly appreciated.
Good idea using a config file to store the values. Can I trick you into pasting an example of your config? Just for inspiration purposes ;)
I'm running Umbraco 4.5.2 for .NET 3.5. It seems like our code is quite similar other than the values of course. I have tried without the protection part, but it's still the same. I'll paste all my code here, just in case I have missed something.
protected void btnCreateMember_Click(object sender, EventArgs e)
{
// Create new member
var member = Membership.CreateUser(txtLoginName.Text, txtPassword.Text, txtEmail.Text);
// Assign role to the new member
Roles.AddUserToRole(member.UserName, ddGroups.SelectedItem.ToString());
// Get the member from Umbraco
var umbracoMember = Member.GetMemberFromLoginName(member.UserName);
// Assign properties to membertype<
umbracoMember.getProperty("navn").Value = txtName.Text;
umbracoMember.getProperty("memberType").Value = "test";
// Create new document
DocumentType dt = DocumentType.GetByAlias("mymembertype");
Document doc = Document.MakeNew(member.UserName, dt, User.GetUser(0), 1112);
// Publish the document
doc.Publish(User.GetUser(0));
umbraco.library.UpdateDocumentCache(doc.Id);
// Protect the document<
Access.ProtectPage(true, doc.Id, 1079, 1083);
Access.AddMembershipUserToDocument(doc.Id, member.UserName);
// If success, let the user know and reset the fields
Response.Write(@"
");
ResetFields();
}
Hopefully the above code example makes sense, if not - please let me know :)
I have also checked in the database for duplicates, but I couldn't find any. It feels like *something* needs to be refreshed, but I don't know what that could be..
Sorry for the delayed response, life goes on in the real world ;)
Thanks for posting your config class, that's pretty neat! However, I was thinking if it was possible to, somehow make a usercontrol for the admins dashboard under a new tab called "Member settings" or something like that, where the admin can set the id's of the nodes if they should change and then grab them in the web.config file. Was just a thought - I don't know if it's too complicated or just plain nonsense ;)
The only thing I can see that's different from how I'm creating members is that you are using the profile provider where I'm using the old umbraco membership stuff. I'm not sure if that makes a difference really.
I've tried to fumble around with the programatically created nodes and it seems that if I move the node (manually) after it's been created, even if I move it to the same parent node, it's double disappears. I don't even have to refresh nodes or anything. Quite strange if you ask me. Of course, I have tried to both move the node, republish all and even tried to do it in an AfterPublish event, but still not working.
/shrug
Thanks for your help so far though! :) appreciated!
You could modify the configuration class to write values back to the XML config file fairly easily, then provide a User Control as an interface to the methods to do that...
What happens if you actually create the document in a Member.AfterSave event ? So when the member is created, use that event to create the document and publish it...
Sounds like a good way to handle the node id configuration part! I'll have to look into that.
I've just tried to make a new test usercontrol where the only thing I do (even from the frontend!) is creating a new node and nothing else. Still, it's showing up twice in the tree. I'm starting to pull out my hair now ;)
instead of using a user control to create the document, what happens if you use events instead? use the Member.AfterSave event handler to create the document after the member is created...
I rethinked it a bit and decided to re-install my test-umbraco just to start over clear.
I skipped the idea of creating a new document when a member is being created and then use the relationship api to relate members to documents. So basically, my create member usercontrol is working now as it should. I then made a new usercontrol to use in the frontend for when members needs to add new documents, here's the code:
protected void btnCreateSpot_Click(object sender, EventArgs e)
{
Member m = Member.GetCurrentMember();
Node parentNode = new Node(1077);
if (Member.IsLoggedOn() && parentNode != null)
{
string partnerType = m.getProperty("medlemstype").Value.ToString();
string partnerGruppe = m.getProperty("medlemsgruppe").Value.ToString();
DocumentType dt = DocumentType.GetByAlias("PartnerSpot");
Document doc = Document.MakeNew("test", dt, User.GetUser(0), parentNode.Id);
doc.getProperty("partner").Value = m.LoginName;
doc.getProperty("partnerType").Value = partnerType;
doc.getProperty("partnerGruppe").Value = partnerGruppe;
doc.getProperty("bodyText").Value = txtSpotText.Text;
doc.Save();
doc.Publish(User.GetUser(0));
umbraco.library.UpdateDocumentCache(doc.Id);
Document.AfterSave += (se, ea) =>
{
RelationType rt = RelationType.GetByAlias("relateMemberToDocument");
Relation.MakeNew(1080, 1050, rt, "Go Further page is now related to Bo Mortensen");
};
}
}
Here i'm trying to create the new document and then relate it to the member that's logged in. As you can see, I even tried to hardcore the id's into the Relation.MakeNew to test it, but I get the error:
Server Error in '/' Application.
Runtime Error
When hitting the create spot button. It seems like absolutely nothing must happen in the code other than creating a new document.. I get the above error if I try to do anything else :/
It's getting annoying when something that should be that easy is taking so long time! But I guess patience is a virtue :)
Ok, just when you would think that it's getting strange, the name of the newly created documents is getting copied after each other as you navigate around in umbraco. If I created a document with the name "test" from the frontend and go to the backend, I will see two of the same node with the name "test", if I then go to the developer section and back to the content section, the name of the nodes are "testtest", if I do it one more time, the names will now be "testtesttest"
Node is being shown twice in content tree
Hi all,
I've just made a usercontrol which is placed on the dashboard in umbraco to create a new member and then create a node assigned to this member. All is working as expected, but when I refresh the content tree, the created note shows up twice (with the same id) I've tried to republish entire site and reload all nodes, but nothing works.
Has anyone ever found a solution to this problem? I have done a search both here on our.umbraco.org, google and stackoverflow.com but I haven't found a way to counter it yet :(
This is how I do it programatically:
DocumentType dt = DocumentType.GetByAlias("mymembertype")
Document doc = Document.MakeNew(member.UserName, dt, User.GetUser(0), 1112);
doc.Publish(User.GetUser(0));
umbraco.library.UpdateDocumentCache(doc.Id);
Access.ProtectPage(true, doc.Id, 1079, 1083);
Access.AddMembershipUserToDocument(doc.Id, member.UserName);
Also, as a side-question: what I don't like about this method is, that I have to hardcode the id of the parent node (1112) and the login and loginerror (1079, 1083) pages. Is there any other, more elegant way of doing this?
Thanks in advance!
Bo
Hey Bo,
Most of the time when I create a user control that needs parameters like the root node, or login pages, etc. I'd create a config file for it and put the configuration details there. Read them out into static variables when the user control is created so you don't have to unecessarily do more disk read operations.
Regarding the duplicate node issue: what version of Umbraco are you using? I'm doing essentially the same thing when creating the document, but not seeing the duplicate node issue. Mind you, I'm not trying to protect the document. My code looks like this:
Hi Robert, thanks for tuning in! :) greatly appreciated.
Good idea using a config file to store the values. Can I trick you into pasting an example of your config? Just for inspiration purposes ;)
I'm running Umbraco 4.5.2 for .NET 3.5. It seems like our code is quite similar other than the values of course. I have tried without the protection part, but it's still the same. I'll paste all my code here, just in case I have missed something.
Hopefully the above code example makes sense, if not - please let me know :)
I have also checked in the database for duplicates, but I couldn't find any. It feels like *something* needs to be refreshed, but I don't know what that could be..
Thanks again.
Bo
Seeing as I'm such a helpful, community minded person :P here's my config class (I basically stole the idea from another project):
When I create a user programmatically, I use the following code:
The last line essentially generates the member xml node, forcing a refresh with the new property values.
Doubt it's going to make a difference though.
Hi again Robert,
Sorry for the delayed response, life goes on in the real world ;)
Thanks for posting your config class, that's pretty neat! However, I was thinking if it was possible to, somehow make a usercontrol for the admins dashboard under a new tab called "Member settings" or something like that, where the admin can set the id's of the nodes if they should change and then grab them in the web.config file. Was just a thought - I don't know if it's too complicated or just plain nonsense ;)
The only thing I can see that's different from how I'm creating members is that you are using the profile provider where I'm using the old umbraco membership stuff. I'm not sure if that makes a difference really.
I've tried to fumble around with the programatically created nodes and it seems that if I move the node (manually) after it's been created, even if I move it to the same parent node, it's double disappears. I don't even have to refresh nodes or anything. Quite strange if you ask me. Of course, I have tried to both move the node, republish all and even tried to do it in an AfterPublish event, but still not working.
/shrug
Thanks for your help so far though! :) appreciated!
All the best,
Bo
Hi Bo,
You could modify the configuration class to write values back to the XML config file fairly easily, then provide a User Control as an interface to the methods to do that...
What happens if you actually create the document in a Member.AfterSave event ? So when the member is created, use that event to create the document and publish it...
Hi again Robert,
Thanks for your patience ;)
Sounds like a good way to handle the node id configuration part! I'll have to look into that.
I've just tried to make a new test usercontrol where the only thing I do (even from the frontend!) is creating a new node and nothing else. Still, it's showing up twice in the tree. I'm starting to pull out my hair now ;)
instead of using a user control to create the document, what happens if you use events instead? use the Member.AfterSave event handler to create the document after the member is created...
I rethinked it a bit and decided to re-install my test-umbraco just to start over clear.
I skipped the idea of creating a new document when a member is being created and then use the relationship api to relate members to documents. So basically, my create member usercontrol is working now as it should. I then made a new usercontrol to use in the frontend for when members needs to add new documents, here's the code:
Here i'm trying to create the new document and then relate it to the member that's logged in. As you can see, I even tried to hardcore the id's into the Relation.MakeNew to test it, but I get the error:
Server Error in '/' Application.
Runtime Error
When hitting the create spot button. It seems like absolutely nothing must happen in the code other than creating a new document.. I get the above error if I try to do anything else :/
It's getting annoying when something that should be that easy is taking so long time! But I guess patience is a virtue :)
All the best,
Bo
Ok, just when you would think that it's getting strange, the name of the newly created documents is getting copied after each other as you navigate around in umbraco. If I created a document with the name "test" from the frontend and go to the backend, I will see two of the same node with the name "test", if I then go to the developer section and back to the content section, the name of the nodes are "testtest", if I do it one more time, the names will now be "testtesttest"
... something is wrong here! :P
Weird, when I tried today on the live version of the site there was no problem, so everything is behaving just as it should now.
Thanks for your help and patience Robert! :)
lol - good to hear :) Was beginning to think there must have been something screwy with your installation...
is working on a reply...