Adding item information

Jun 22, 2007 at 2:47 PM
Hi,
Thank you very much for this great project and for sharing the code.
This project shows how to add a context menu to each item. As being quite a novice to Sharepoint Programming I would like know if it is possible to add some information directly to the item .e.g. adding an icon which shows the type of document right next to the item (similar to the document web part). As this information cannot be drawn from site columns directly this approach needs some coding. In your project you use this information in the context menu - can you please give me a hint as what I would need to code to show this information on-line with the item?
Thank you very much,
DD
Coordinator
Jun 23, 2007 at 3:25 AM
DD,
If you look in the code you will notice that I get the URL to the file type icon image from the SPFile object (IconUrl).
Here it is:

if (this.ListItem != null && this.ListItem.File != null)
{
return this.ListItem.File.IconUrl;
}

If you want to know how sharepoint is getting it - it is from DOCICON.XML file which I am using to get the "edit in ??? application" text: (pathToFile is the path to DOCICON.XML)

XmlDocument docs = new XmlDocument();
docs.Load(pathToFile);
XmlNode docNode = docs.DocumentElement.SelectSingleNode("//Mapping@Key='" + this.ItemExtension + "'");
if (docNode != null)
{
string editText = "";
if (docNode.Attributes"EditText" != null)
editText = docNode.Attributes"EditText".Value;

editText += "|";

if (docNode.Attributes"OpenControl" != null)
editText += docNode.Attributes"OpenControl".Value;

return editText;
}
Jun 23, 2007 at 9:39 PM
Hello ishaisagi,

Thank you very much for taking the time to reply to my question.

Unfortunately I'm not completly getting the concept behind overriding the ouptut.
Let's say I would like to add an additional item to a displayed list:

.....

private Microsoft.SharePoint.SPWeb _web = null;
private Microsoft.SharePoint.SPList _mysheetList = null;

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{

try
{
//get the web
this._web = Microsoft.SharePoint.SPContext.Current.Web;
//get the mysheet list
this.mysheetList = this.web.Lists“Mysheet”;
int iAdditionalInfo=0;
foreach (SPListItem i in this._mysheetList.Items)
{
iAdditionalInfo += 10;
}
writer.Write(“The additional info is {0}”,i.ToString());
}

If I understand correctly, I would override Render() with additional info per item (in the above case a Sharepoint List is used).

But how would I go with the Content Query WebPart - how would I access the currently displayed items of a Content Query? Is this also a list where I would use e.g. a foreach SPListItem where I would add additional information to the current item? And if I remember correctly (sorry but I don't have access to the code at the time of writing this post) you're adding the context menu outside of Render but without calling a method within Render - when and where would the alteration of a current item of the Content Query happen.

Sorry to bother you with this propably basic question.

Thank you very much.
Regards,
DD
Coordinator
Jun 24, 2007 at 11:25 PM
DD,
your questions (and code) show that you need some kind of training or reading about .net development and custom controls.

Using the "render" event is too late in the web part's life time to do some tasks, and in my web part I am using it for only specific tasks that need to go at that stage. Some other tasks go at the CreateChildControls for example - to add server side controls (search my blog for "Server Side Controls" and "events")

If you want to learn how to get the items that a content query web part got, just look at my code. it has exactly that. Hint - "ProcessDataDelegate":
//force a call the ProcessItems function when ProcessData event is triggered.
this.ProcessDataDelegate = new ProcessData(ProcessItems);

Jul 9, 2007 at 8:04 AM
Had a look at sharepoint-tips and a lot of things are clearer now - thanks for the help