Microsoft Content Management Server - setting the custom properties programmatically - CmsApplicationContext

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > January 2006 > setting the custom properties programmatically - CmsApplicationContext





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author setting the custom properties programmatically - CmsApplicationContext
Burak Kadirbeyoglu

2006-01-29, 9:09 pm

Dear CMS Developers,

I want to set the values of custom properties of the postings created from a
specific template programmatically. I'm using following code in
global.asax.cs:

public void CmsPosting_Creating(Object sender, CreatingEventArgs e)
{
CmsApplicationContext cmsAppContext = new CmsApplicationContext();
cmsAppContext. AuthenticateAsCurrentUser(PublishingMode
.Update);
string GUID = CmsHttpContext.Current.Posting.Guid;
Posting posting = (Posting) cmsAppContext.Searches.GetByGuid(GUID);

if (posting.Template.SourceFile == "/Templates/TR/Default/News.aspx")
{
posting.CustomProperties["DAY"].Value = "8";
cmsAppContext.CommitAll();
}
}

When I'm saving a new posting, the following exception is thrown:

Login attempt failed. Access is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Login
attempt failed. Access is denied.

I guess it's related with CmsApplicationContext, isn't it? Can I use
CmsHttpContext instead?

Thanks in advance,

Burak Kadirbeyoğlu


Stefan [MSFT]

2006-01-29, 9:09 pm

Hi Burak,

see my parallel response to your other post.

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------


"Burak Kadirbeyoglu" <bkadirbeyoglu@protel.com.tr> wrote in message
news:Ot1qG9mIGHA.1032@TK2MSFTNGP11.phx.gbl...
> Dear CMS Developers,
>
> I want to set the values of custom properties of the postings created from
> a specific template programmatically. I'm using following code in
> global.asax.cs:
>
> public void CmsPosting_Creating(Object sender, CreatingEventArgs e)
> {
> CmsApplicationContext cmsAppContext = new CmsApplicationContext();
> cmsAppContext. AuthenticateAsCurrentUser(PublishingMode
.Update);
> string GUID = CmsHttpContext.Current.Posting.Guid;
> Posting posting = (Posting) cmsAppContext.Searches.GetByGuid(GUID);
>
> if (posting.Template.SourceFile ==
> "/Templates/TR/Default/News.aspx")
> {
> posting.CustomProperties["DAY"].Value = "8";
> cmsAppContext.CommitAll();
> }
> }
>
> When I'm saving a new posting, the following exception is thrown:
>
> Login attempt failed. Access is denied.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.Runtime.InteropServices.COMException: Login
> attempt failed. Access is denied.
>
> I guess it's related with CmsApplicationContext, isn't it? Can I use
> CmsHttpContext instead?
>
> Thanks in advance,
>
> Burak Kadirbeyoğlu
>



Burak Kadirbeyoglu

2006-01-29, 9:09 pm

Thanks Stefan, I solved it the following way without using a
CmsApplicationContext object:

public void CmsPosting_Created(Object sender, CreatedEventArgs e)
{
Posting p = (Posting) e.Target;
if (p.Template.SourceFile == "/Templates/TR/Default/News.aspx")
{
DateTime date;
date = DateTime.Now;
p.CustomProperties["DAY"].Value = date.ToString("dd");
p.CustomProperties["MONTH"].Value = date.ToString("MM");
p.CustomProperties["YEAR"].Value = date.ToString("yyyy");
}
}

Regards,

Burak

"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
news:uZbUVynIGHA.3896@TK2MSFTNGP15.phx.gbl...
> Hi Burak,
>
> see my parallel response to your other post.
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS:
> http://tinyurl.com/6zj44
> Check out the new book as well: Advanced MCMS development:
> http://tinyurl.com/8ugwj
> ----------------------
>
>
> "Burak Kadirbeyoglu" <bkadirbeyoglu@protel.com.tr> wrote in message
> news:Ot1qG9mIGHA.1032@TK2MSFTNGP11.phx.gbl...
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com