Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
SelectedNRTDocuments
Kes
Hi everyone, this may be a stupid question but please be patient.
I have started writing worksite custom commands and I have a problem with my code where the error message "Specified cast is not valid" occurs.
The example in CUSTOMCOMMANDS is written in VB and would like a conversion of this code in C# please.
Here is my code:
public void Initialize(ContextItems Context)
{
this._context = Context;
}
public void Update()
{
IManage.NRTDocument[] imNRTDocuments;
imNRTDocuments = new IManage.NRTDocument[10]
imNRTDocuments = (IManage.NRTDocument[]) this._context.Item("SelectedNRTDocuments")
//was going to iterate through imNRTDocuments to look at document
//extensions but above falls over.
}
The above falls over when we assign imNRTDocuments with the context item.
The above routine is so that I can get the selected documents a user has selected when they right click on the selection.
I know I am doing something seriously wrong here and it's probably due to my ignorance, but can anybody please help me.
Find more posts tagged with
Comments
jny
// The documents that the user has selected
Array rpSelectedDocuments = (Array)mContext.Item("SelectedNRTDocuments");
// Gets each element in the array.
IManDocument doc = (IManDocument) rpSelectedDocuments.GetValue(0);
("SelectedNRTDocuments");
IManDocument doc = null;
for(int i=0; i<= rpSelectedDocuments.Length; i++)
{
doc = (IManDocument)rpSelectedDocuments.GetValue(i);
}
Kes
Thanks so much, I will try that out since it looks better than what I eventually did, see below.
I also got this working using the following code and I still have no idea why this works and why the context.item("SelectedNRTDocuments") returns an array which can be parsed as System Objects instead of an array of NRTDocuments.
try
{
System.Object[] oSysObj = new Object[0];
oSysObj = (System.Object[]) _context.Item("SelectedNRTDocuments");
foreach(IManage.NRTDocument NRTDoc in oSysObj)
{
MessageBox.Show("Document = " + NRTDoc.Description.ToString());
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}