help with a web part code from an MSDN Article
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
help with a web part code from an MSDN Article

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
Parrothead
Guest





Posted: Tue Jan 04, 2005 8:53 pm    Post subject: help with a web part code from an MSDN Article Reply with quote

I have been trying to get this web part called "Documents today" to work. it
is from the MSDN article called "how to customize your search using SPS 2003."

I have compiled to code, and loaded it registers as safe, but the web part
doesn't do anything...nothing no errors.

I was wodnering if some one out there might be able to point out what is
needed to be changed or fixed in order for this webpart to work.

Code is below:
using System;
using System.Data;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal.Search;
using Microsoft.SharePoint.Portal;

namespace documentstoday
{
/// <summary>
/// Description for WebPart1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:documentstoday runat=server></{0}:documentstoday>"),
XmlRoot(Namespace="documentstoday")]
public class documentstoday : Microsoft.SharePoint.WebPartPages.WebPart
{

private Label labelResults = null;

protected override void CreateChildControls()
{
this.labelResults = new Label();

DataSet ds = null;
try
{
PortalContext context = PortalApplication.GetContext();
QueryProvider qp = new QueryProvider(context.SearchApplicationName);
string query =
"SELECT \"DAV:href\",\"DAV:displayname\",
\"urn:schemas-microsoft-com:office:office#Author\" " +
"FROM Portal_Content..Scope() " +
"WHERE (\"urn:schemas.microsoft.com:sharepoint:portal:isdocument\" = 1)
AND " +
"(\"DAV:creationdate\" > DateAdd(Day, -1, GetGMTDate()))";
ds = qp.Execute(query);

StringBuilder sb = new StringBuilder();

if(ds != null)
{
sb.Append("<UL>");
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.AppendFormat("<LI><A href='{0}'>{1}</A> added by {2}</LI>",
dr["DAV:href"].ToString(),dr["DAV:displayname"].ToString(),
dr["urn:schemas-microsoft-com:office:office#Author"].ToString());
}
sb.Append("</UL>");
}
else
{
sb.Append("<P>No new documents added today</P>");
}

this.labelResults.Text = sb.ToString();
}
catch (Exception ex)
{
this.labelResults.Text = ex.ToString();
}

this.Controls.Add(this.labelResults);
}


protected override void RenderWebPart(HtmlTextWriter output)
{
this.EnsureChildControls();
this.labelResults.RenderControl(output);
}
}
}
Back to top
Parrothead
Guest





Posted: Tue Jan 04, 2005 9:39 pm    Post subject: RE: help with a webpart code from an MSDN Article(Error Code Reply with quote

this is the error code that the web part generates:
System.NullReferenceException: Object reference not set to an instance of an
object. at documentstoday.documentstoday.CreateChildControls() in
c:\documents and settings\atheysd\my documents\visual studio
projects\documentstoday\documentstoday.cs:line 35


Quote:
I have been trying to get this web part called "Documents today" to work. it
is from the MSDN article called "how to customize your search using SPS 2003."

I have compiled to code, and loaded it registers as safe, but the web part
doesn't do anything...nothing no errors.

I was wodnering if some one out there might be able to point out what is
needed to be changed or fixed in order for this webpart to work.

Code is below:
using System;
using System.Data;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal.Search;
using Microsoft.SharePoint.Portal;

namespace documentstoday
{
/// <summary
/// Description for WebPart1.
/// </summary
[DefaultProperty("Text"),
ToolboxData("<{0}:documentstoday runat=server></{0}:documentstoday>"),
XmlRoot(Namespace="documentstoday")]
public class documentstoday : Microsoft.SharePoint.WebPartPages.WebPart
{

private Label labelResults = null;

protected override void CreateChildControls()
{
this.labelResults = new Label();

DataSet ds = null;
try
{
PortalContext context = PortalApplication.GetContext();
QueryProvider qp = new QueryProvider(context.SearchApplicationName);
string query =
"SELECT \"DAV:href\",\"DAV:displayname\",
\"urn:schemas-microsoft-com:office:office#Author\" " +
"FROM Portal_Content..Scope() " +
"WHERE (\"urn:schemas.microsoft.com:sharepoint:portal:isdocument\" = 1)
AND " +
"(\"DAV:creationdate\" > DateAdd(Day, -1, GetGMTDate()))";
ds = qp.Execute(query);

StringBuilder sb = new StringBuilder();

if(ds != null)
{
sb.Append("<UL>");
foreach(DataRow dr in ds.Tables[0].Rows)
{
sb.AppendFormat("<LI><A href='{0}'>{1}</A> added by {2}</LI>",
dr["DAV:href"].ToString(),dr["DAV:displayname"].ToString(),
dr["urn:schemas-microsoft-com:office:office#Author"].ToString());
}
sb.Append("</UL>");
}
else
{
sb.Append("<P>No new documents added today</P>");
}

this.labelResults.Text = sb.ToString();
}
catch (Exception ex)
{
this.labelResults.Text = ex.ToString();
}

this.Controls.Add(this.labelResults);
}


protected override void RenderWebPart(HtmlTextWriter output)
{
this.EnsureChildControls();
this.labelResults.RenderControl(output);
}
}
}
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB