|
Home > Archive > Microsoft Content Management Server > June 2004 > How can I stop authors from saving pages with identical names?
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 |
How can I stop authors from saving pages with identical names?
|
|
| Morten Petterĝe 2004-04-27, 12:36 pm |
| Hi,
I have told all authors that we must be careful not to enter duplicate
posting names in one channel. This will break a lot of language switching
code that I have on my multilingual website.
Is there an easy ( or hard for that matter ) way of implementing a check
when the user clicks "Save New Page" so that I can throw a simple
PublishingException or something if a page with the same name already
exists?
Any help is appreciated.
Thanks,
Morten
| |
| Stefan [MSFT] 2004-04-27, 2:36 pm |
| Hi Morten,
I would suggest to either implement a custom save console action and test if
a posting with identical name exits.
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Morten Petterĝe" <morten@imano.nospam (remove the spam, leave the no)>
wrote in message news:e$fgx$GLEHA.624@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I have told all authors that we must be careful not to enter duplicate
> posting names in one channel. This will break a lot of language switching
> code that I have on my multilingual website.
>
> Is there an easy ( or hard for that matter ) way of implementing a check
> when the user clicks "Save New Page" so that I can throw a simple
> PublishingException or something if a page with the same name already
> exists?
>
> Any help is appreciated.
>
>
> Thanks,
>
> Morten
>
>
| |
| Morten Petterĝe 2004-04-30, 7:35 am |
| Hi again,
I have tried to do this by implementing an eventhandler on the created
event. But when I check for the name of the posting (e.Target.Name), this
always returns the name of the Template. What do I do to get the actual name
that the user has entered for this posting?
Thanks,
Morten
"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
news:uAzrlfILEHA.556@tk2msftngp13.phx.gbl...
> Hi Morten,
>
> I would suggest to either implement a custom save console action and test
if
> a posting with identical name exits.
>
> Cheers,
> Stefan.
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>
>
> "Morten Petterĝe" <morten@imano.nospam (remove the spam, leave the no)>
> wrote in message news:e$fgx$GLEHA.624@TK2MSFTNGP11.phx.gbl...
switching[vbcol=seagreen]
check[vbcol=seagreen]
>
>
| |
| Stefan [MSFT] 2004-04-30, 1:37 pm |
| Hi Morten,
the name is applied with a changed event handler later.
But the name is already available in a Request.Form variable (you need to
check which one as I don't have the info avail at the moment).
More elegant is the solution with a modified console action.
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Morten Petterĝe" <morten@imano.nospam (remove the spam, leave the no)>
wrote in message news:OFdcODqLEHA.1032@TK2MSFTNGP12.phx.gbl...
> Hi again,
>
> I have tried to do this by implementing an eventhandler on the created
> event. But when I check for the name of the posting (e.Target.Name), this
> always returns the name of the Template. What do I do to get the actual
name
> that the user has entered for this posting?
>
>
> Thanks,
>
> Morten
>
> "Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message
> news:uAzrlfILEHA.556@tk2msftngp13.phx.gbl...
test[vbcol=seagreen]
> if
> rights.
> switching
> check
>
>
| |
| Mikey_Doc 2004-05-11, 8:20 pm |
| Hi Morten
The solution we use (Ok its not particularly elegant) is t0 catch the
propertyChanging event in the Global.aspx file.
If the user has typed a duplicate file name we append the code with
the date and the 'XXXX'. The console checks current posting name and
if it sees the XXXX it generates a message saying that this is a
duplicate posting (Even though it isn't as the name has been changed.
As I say not particularly elegant but it does the job.
(Here the code is checking he file name but a minor change would let
it check the display name)
Please note the minimalist approach to comments.
Mikey
Protected Sub CmsPosting_PropertyChanging(ByVal sender As Object,
ByVal e As PropertyChangingEventArgs)
Dim p As Posting
If e.Target().getType().Name = "Posting" Then
p = e.Target
Dim propName As String = e.PropertyName
Dim tname As String = ""
If propName = "Name" Then
If CheckForDuplicateName(p, e.PropertyValue) Then
e.PropertyValue = e.PropertyValue +
DateTime.Now.ToString("dd-MMM-yyyy HH-mm-ss") & "xxxx"
End If
End If
End If
End Sub
Private Function CheckForDuplicateName(ByVal p As Posting, ByVal
val As String) As Boolean
Dim ch As Microsoft.ContentManagement.Publishing.Channel =
CmsHttpContext.Current.Channel()
Dim post As Posting
post = ch.Postings(val)
If Not post Is Nothing Then
Return True
End If
Return False
End Function
"Stefan [MSFT]" <stefang@online.microsoft.com> wrote in message news:<#cRCYUtLEHA.624@TK2MSFTNGP11.phx.gbl>...[vbcol=seagreen]
> Hi Morten,
>
> the name is applied with a changed event handler later.
> But the name is already available in a Request.Form variable (you need to
> check which one as I don't have the info avail at the moment).
> More elegant is the solution with a modified console action.
>
> Cheers,
> Stefan.
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> "Morten Petterĝe" <morten@imano.nospam (remove the spam, leave the no)>
> wrote in message news:OFdcODqLEHA.1032@TK2MSFTNGP12.phx.gbl...
> name
> test
> if
> rights.
> switching
> check
| |
| Sandeep 2004-06-11, 6:49 pm |
| Here is another possible solution that actually cancels
the save:
In the global.asa:
public void CmsPosting_Creating( Object sender,
CreatingEventArgs e )
{
string postingName = Request.Form
["WBC_fieldNewPageName"];
if (IsDuplicatePosting(postingName.Trim()))
{
e.Cancel = true;
}
}
private bool IsDuplicatePosting(string postingName)
{
Logging.LogTrace(Logging.MethodCalledString);
try
{
foreach (Posting p in
currentCmsContext.Channel.Postings)
{
if (p.Name==postingName) return
true;
}
}
catch
{
return true;
}
return false;
}
To return a friendly error to the user as a replacement
for the default error message displayed, add the
following in the console control pre-render event:
private void Console1_PreRender(object sender,
System.EventArgs e)
{
if (ErrorModeContainerFailedCreate1.Visible)
{
if
(ErrorModeContainerFailedCreate1.Error.Exception.Message.I
ndexOf("custom event handler")!=-1)
{
errorMessage = "Save failed due
to duplicate name";
}
else
errorMessage =
ErrorModeContainerFailedCreate1.Error.Exception.Message;
}
}
| |
| Sandeep 2004-06-20, 11:03 pm |
| Here is another possible solution that actually cancels
the save:
In the global.asa:
public void CmsPosting_Creating( Object sender,
CreatingEventArgs e )
{
string postingName = Request.Form
["WBC_fieldNewPageName"];
if (IsDuplicatePosting(postingName.Trim()))
{
e.Cancel = true;
}
}
private bool IsDuplicatePosting(string postingName)
{
Logging.LogTrace(Logging.MethodCalledString);
try
{
foreach (Posting p in
currentCmsContext.Channel.Postings)
{
if (p.Name==postingName) return
true;
}
}
catch
{
return true;
}
return false;
}
To return a friendly error to the user as a replacement
for the default error message displayed, add the
following in the console control pre-render event:
private void Console1_PreRender(object sender,
System.EventArgs e)
{
if (ErrorModeContainerFailedCreate1.Visible)
{
if
(ErrorModeContainerFailedCreate1.Error.Exception.Message.I
ndexOf("custom event handler")!=-1)
{
errorMessage = "Save failed due
to duplicate name";
}
else
errorMessage =
ErrorModeContainerFailedCreate1.Error.Exception.Message;
}
}
| |
| Stefan [MSFT] 2004-06-26, 10:49 am |
| Hi Teri,
yes.
See the following sample:
http://www.gotdotnet.com/Community/...e7-56dd30bb89fe
Cheers,
Stefan.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
MCMS FAQ:
http://download.microsoft.com/downl...6a/MCMS+2002+-+(complete)+FAQ.htm
MCMS Blog: http://blogs.msdn.com/stefan_gossner/category/4983.aspx
MCMS Sample Code:
http://www.gotdotnet.com/community/...t+S
erver
MCMS Whitepapers and other docs:
http://blogs.msdn.com/stefan_gossne...2/07/41859.aspx
--------------------------------
"Teri" <Teri@discussions.microsoft.com> wrote in message
news:E774EC69-CD46-4792-8103-17F5898DF1A3@microsoft.com...
> I tried to post a new message but... the drop down for the required "post
in discussion group" wouldn't populate. My question is similar to this
topic.
>
> Is it possible to populate the Name and Display Name fields on the Save
New Page popup? On specific templates (Ex: news article postings) we would
like the name of the page to begin with the release date of the article
(YYYYMMDD). We can then sort the articles by name to get them in date
order. We are able to rename the page on re-edit save. We have also been
able to populate the hidden variable WBC_fieldNewPageName via javascript.
Unfortunately it looks like the Save New Page popup is not reading this
hidden variable. We are out of ideas. Any assitance is appreciated.[vbcol=seagreen]
>
> Thanks,
> Teri
>
> "Sandeep" wrote:
>
|
|
|
|
|