SharePoint 2010 Custom WebPart List Deleted Message

Quick and Easy, just make sure to type the exact name of the Lists \ Libraries inside the code:

  • Open VS 2010 and Create new Project as Visual Web Part Project.
  • 3 tips need to be consider and that is : make sure .Net Framework is 3.5 – Platform Target to be 64 bit or Any CPU – last one is to Add Microsoft.SharePoint.dll in the reference.
  • In ASCX File, add following code:
    <ul id=”ticker02″ class=”newsticker”>
    <%=OutPut %>
    <asp:Label runat=”server” ID=”Label1″ Text=””></asp:Label>
  • In CS File, add following code, I have used CAML Query Bulider to get below query:
  • Don’t forget to add following string in the top:

public string OutPut;

protected void Page_Load(object sender, EventArgs e)

using (SPSite spSite = new SPSite(“Site Name”))
using (SPWeb oWebSite = spSite.OpenWeb())
SPList oGetList = oWebSite.Lists.TryGetList(“List Name”);
if (oGetList != null)

SPDocumentLibrary oDocumentLibrary = (SPDocumentLibrary)oWebSite.Lists[“Same List Name”];
SPQuery query = new SPQuery();
query.RowLimit = 5;

query.Query = “<Where><IsNotNull><FieldRef Name=’Title’ />” +
“</IsNotNull></Where>” +
“<OrderBy><FieldRef Name=’Modified’ Ascending=’False’ /></OrderBy>”;

SPListItemCollection colitem = oDocumentLibrary.GetItems(query);

foreach (SPListItem oItem in colitem)
OutPut = OutPut + “<li><a href=’URL if needed” + oItem[“ows_LinkFilename2”].ToString() + “‘>” + oItem[“Title”].ToString() + ” ” + “</a></li>”;
Label1.Text = “List does not exist in the site”;


Happy Coding !!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s